$emit(update: prop, "newPropVulue") /.sync 修饰符:子组件向父组件传达:更新属性

$emit(update: prop, "newPropVulue")  这个模式,使子组件向父组件传达:更新属性,并抛出新的属性值

.sync 修饰符 是以上模式的简写

$emit(update: prop, "newPropVulue")  模式:

用 title 举例:

在声明了 title 这个 prop 的子组件中,创建一个方法, 使用 this.$emit('update:title', newTitle)

然后父组件中用 v-on 监听 v-on:update:title="doc.title=$event"

这里的 $event 取得值是 子元素 $emit('update:title', newTitle) 里面抛出来的 newTitle 这个参数 (具体查看:$event :父组件获取子组件 $emit(event, args) 抛出的值 args

所以父组件的 doc.title 的值会更新为子组件传来的参数: doc.title=newTitle 

.sync 修饰符:

简写以上的模式

可以直接传入一个doc (包含多个prop值的集合) 

注意:

猜你喜欢

转载自blog.csdn.net/weixin_41796631/article/details/83051966
今日推荐