向上传递:子组件触发,父组件响应
在子组件
this.$emit('fromSon', {
showPreviewImg:false
})
image.png
在父组件
<block if="{{showPreviewImg}}">
<previewImg preview-img-list="{{previewImgList}}" @from-son="closeImgModal"></previewImg>
</block>
image.png
// 接受子组件传递的值
closeImgModal(evt) {
this.showPreviewImg = evt.detail.showPreviewImg
},
image.png
向下传递:父组件触发,子组件响应
在父组件
this.$broadcast('sendSon', { showPreviewState: this.showPreviewState })
image.png
在子组件
this.$on('sendSon', this.sendSonHandler)
sendSonHandler(evt) {
// console.info(`子组件:事件响应: `, evt.type, evt.detail);
this.showPreviewImg = evt.detail.showPreviewState;
// 结束事件传递
evt.stop()
},
image.png