两者共同点
v-model的本质
<!--v-model写法-->
<my-component type="text" v-model="value">
<!--展开语法糖后的写法-->
<my-component type="text"
:value="value"
@input="value = $event.target.value"
>
<!--
默认针对原生组件input事件,但是如果子组件定义了针对事件
model: {
prop: "value",
event: "update"
},
则编译为
-->
<my-component type="text"
:value="value"
@update="(val) => value = val"
>
.sync本质
<!--语法糖.sync-->
<my-component :value.sync="value" />
<!--编译后的写法-->
<my-component
:value="msg"
@update:value="(val) => value = val"
>
两者本质都是一样,并没有任何区别: “监听一个触发事件”="(val) => value = val"。
细微之处的区别
1.只不过v-m