Home > Article > Web Front-end > What is the usage of vue bus?
Usage of vue bus: 1. Install vue-bus through "npm install vue-bus"; 2. Introduce vue-bus in main.js; 3. Through "this.$bus.emit(. ..);" and other methods can be used in the component.
The operating environment of this article: Windows 7 system, Vue2.9.6, Dell G3 computer.
What is the usage of vue bus?
How to use Bus in Vue:
Usage: pass values between sibling components;
Installation:
npm install vue-bus
Introduce vue-bus in main.js
import Vue from 'vue'; import VueBus from 'vue-bus'; Vue.use(VueBus);
In the component Used in:
A component triggers events:
this.$bus.emit("parameterName",params);
B component receives events:
this.$bus.on("parameterName",function(value){ console.log(value) });
Unbind the event when the component is destroyed:
destroyed:function(){ this.$bus.off("parameterName") }
Recommended: "The latest 5 vue.js video tutorial selections"
The above is the detailed content of What is the usage of vue bus?. For more information, please follow other related articles on the PHP Chinese website!