Appearance
27.Vue 中.sync 修饰符的作用?
在有些情况下,我们可能需要对一个 prop 进行“双向绑定”,这时可以使用.sync来实现。v-model默认只能双向绑定一个属性,这里就可以通过.sync修饰符绑定多个属性。
vue
<my :value.sync="xxxx"></my>
<!--编译的结果是
with(this){
return _c('my',{
attrs:{"value":xxxx},
on:{"update:value":function($event){xxxx=$event}}
})
}--><my :value.sync="xxxx"></my>
<!--编译的结果是
with(this){
return _c('my',{
attrs:{"value":xxxx},
on:{"update:value":function($event){xxxx=$event}}
})
}-->vue3 中
.sync语法被移除。