v-model
绑定的不再是value
,而是modelValue
,接收的方法也不再是input
,而是update:modelValue
。使用方法如下:
<ChildComponent v-model = "title">
它是下面这种写法的简写:
<ChildComponent :modelValue = "title" @update:modelValue = "title = $event">
在子组件中写法是:
export default defineComponent({
name:"ValidateInput",
props:{
modelValue:String, // v-model绑定的属性值
},
setup(){
const updateValue = (e: KeyboardEvent) => {
context.emit("update:modelValue",targetValue); // 传递的方法
}
}
}
标签:写法,绑定,基础,update,Vue3,model,modelValue
From: https://www.cnblogs.com/HaruhiSuzumiya/p/16736969.html