js

梗概

注意

新版本语法糖

<!-- Child.vue -->
<script setup>
const model = defineModel()
function update() {
  model.value++
}
</script>
<template>
  <div>parent bound v-model is: {{ model }}</div>
</template>

旧版本: 通过计算属性

1. 实例:

<script setup>
const props = defineProps(['modelValue'])
const emit = defineEmits(['update:modelValue'])
</script>
<template>
  <input
    :value="props.modelValue"
    @input="emit('update:modelValue', $event.target.value)"
  />
</template>

2. 说明:

  1. child::Vue 自定义更新事件
  2. child::v-model指令