在有些情况下,我们可能需要对一个 prop 进行“双向绑定”。2.3.0+ 新增.sync
修饰符,可以实现prop双向绑定。
举个例子,在一个包含title prop的子组件中,
props: {
title: '',
},
可以用以下方法赋新值:
this.$emit('update:title', newTitle)
然后在父组件中:
<child-component :title.sync="啦啦啦"></child-component>
在有些情况下,我们可能需要对一个 prop 进行“双向绑定”。2.3.0+ 新增.sync
修饰符,可以实现prop双向绑定。
举个例子,在一个包含title prop的子组件中,
props: {
title: '',
},
可以用以下方法赋新值:
this.$emit('update:title', newTitle)
然后在父组件中:
<child-component :title.sync="啦啦啦"></child-component>