.首先随便哪儿写个bus。js
内容如下:
import Vue from 'vue' export default new Vue;
2.在需要通信的组件都引入Bus.js (两兄弟都要引入)
如上图所示大儿子按钮触发事件,$emit 传数据,另一个兄弟组件mounted接受,$on接受数据搞定
![ac982b08ec5b05aef6306447bf03fae4.png](https://img-blog.csdnimg.cn/img_convert/ac982b08ec5b05aef6306447bf03fae4.png)
![012e637185de4341b2d449ea5e2db733.png](https://img-blog.csdnimg.cn/img_convert/012e637185de4341b2d449ea5e2db733.png)
![60d6c1a722b2e6082a698cbd3814bc89.png](https://img-blog.csdnimg.cn/img_convert/60d6c1a722b2e6082a698cbd3814bc89.png)
![8c3de7112ae5d6825ed4cd3ee9dcb12a.png](https://img-blog.csdnimg.cn/img_convert/8c3de7112ae5d6825ed4cd3ee9dcb12a.png)
.首先随便哪儿写个bus。js
内容如下:
import Vue from 'vue' export default new Vue;
2.在需要通信的组件都引入Bus.js (两兄弟都要引入)
如上图所示大儿子按钮触发事件,$emit 传数据,另一个兄弟组件mounted接受,$on接受数据搞定