foreword
Communication requirements between parent and child components are very common. This article mainly introduces the communication between two unrelated sibling components.
Using an EventBus
event bus, which allows two subcomponents to communicate directly,
And there is no need to involve parent components, and the coupling is low, so it is recommended.
first step
Define a new
Vue
instance as a bridge for communication between components , only in this way can two unrelated components be associated.
Create a new project anywhere in the project bus.js
and write the following code:
import Vue from 'vue'
export default new Vue()