兄弟没有共同的父级
创建空的Vue实例对象
// main.js
// 创建空的Vue实例
var eventBus = new Vue()
// 把Vue空实例挂载到Vue的原型上面
Vue.prototype.eventBus = eventBus
创建a组件
<template>
<div>
我是child - a组件
<button>传递数给b组件</button>
</div>
</template>
创建b组件
<template>
<div>
我是child - b组件
</div>
</template>
在a组件中通过this.eventBus.$emit进行数据的传递
this.eventBus.$emit('sendData', this.dataA)
在b组件中通过this.eventBus.$on进行数据的监听接收
this.eventBus.$on('sendData', val => {
this.receiveData = val
})
完整代码
// main.js
// 创建空的Vue实例
var event