有时候我们会发现公司中有这样的代码
<dialog :addUserName.sync="addUserName"></dialog>
开始有点迷惑,因为以前没有接触到过这个语法糖还可以这样用,在使用写轮眼之后算是明白了使用方法
<div class="">
<button type="default" @click="ok">子组件点击</button>
</div>
props:{
addUserName:{
type: string,
default: '',
},
},
methods:{
ok(){
this.$emit('update:refbool',"xiaoming")
}
}
它的用法是不用调用父组件的函数,直接可以修改父组件的值。