Home  >  Article  >  Web Front-end  >  What is the usage of vue bus?

What is the usage of vue bus?

藏色散人
藏色散人Original
2021-10-26 14:13:288963browse

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.

What is the usage of vue bus?

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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Previous article:vue cum yong ie 几Next article:vue cum yong ie 几