Vue - Sibling Component Communication (eventBus)

foreword

Communication requirements between parent and child components are very common. This article mainly introduces the communication between two unrelated sibling components.

Using an EventBusevent 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.
insert image description here

first step

Define a new Vueinstance 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.jsand write the following code:

import Vue from 'vue'
export default new Vue()

second step

Guess you like

Origin blog.csdn.net/weixin_44198965/article/details/123654416