EventBus profile
EventBus is also called an EventBus. You can use EventBus in Vue for cross-component and sibling communicationCopy the code
The use of the EventBus
Using EventBus in VUE can be divided into three steps
- Mount EventBus in main.js
- Send events on page A
- Listen for events on page B
Mount the EventBus
$Bus = new Vue() $Bus = new Vue()Copy the code
Use the EventBus
Send events in the A component
This.$Bus.$emit('busClick',' I am A message from A page ')Copy the code
Listen for events in the B component
// this.$Bus.$on to listen for EvenBus events // Created () {this.$Bus.$on('busClick',(res)=>{console.log(res,' listen '); })}Copy the code