What is the usage of vue bus?
Oct 26, 2021 pm 02:13 PMUsage 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!

Hot Article

Hot tools Tags

Hot Article

Hot Article Tags

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

The difference between event and $event in vue

The difference between export and export default in vue

Onmounted in vue corresponds to which life cycle of react
