父组件
<componentTree v-show="panelShow" :panelShow="panelShow" @add-comment="getDate" @setValue="setValue"></componentTree>
setValue(res) {
this.panelShow = res
},
子组件
props:{
panelShow: {
type: Boolean
}
},
// 改变父组件的值
this.$emit('setValue',false); // 关闭弹框的传值
this.$emit('add-comment')
本文介绍了一个Vue应用中,如何通过props和$emit实现父组件与子组件之间的数据传递与状态同步。具体展示了子组件如何使用$emit触发父组件的方法,以及父组件如何监听子组件的事件并更新状态。
1873

被折叠的 条评论
为什么被折叠?



