vue3的setup中如何使用v-model

539 阅读1分钟

vue3 中当父组件使用了 v-model,到子组件其实是将其分成了modelValue 和 update:modelValue。其中 modelValue 相当于vue2中的 value,update:modelValue 相当于vue2中的 @input

// 父组件
<CustomInput v-model="searchText" />
// 子组件
const props = defineProps(['modelValue'])
const emit = defineEmits(['update:modelValue'])