你如何通过 eventBus 总线将更新传送到 Vue 组件中的视图? [英] How do you eventBus a bus to communicate updates to a view in a Vue component?

查看:19
本文介绍了你如何通过 eventBus 总线将更新传送到 Vue 组件中的视图?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

侦听组件 b 中总线的自定义事件.但是,在组件 a 中调度事件后,它访问组件 b.组件b的监听函数执行了,但是数据函数的msg没有更新

请不要说Vuex.

相关代码基于Vue CLi3

这里的代码:组件A:

 <模板><div>组分 A<button @click="sendMsg">pushB</button>

<脚本>从'./bus'导入总线导出默认{方法: {发送消息(){bus.$emit('send', '你好组件B')this.$router.push('/bbb')}}}

组件B: