Home Web Front-end Vue.js What is the usage of vue bus?

What is the usage of vue bus?

Oct 26, 2021 pm 02:13 PM
vue

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
Copy after login

Introduce vue-bus in main.js

import Vue from 'vue';
import VueBus from 'vue-bus';
 
Vue.use(VueBus);
Copy after login

In the component Used in:

A component triggers events:

this.$bus.emit("parameterName",params);
Copy after login

B component receives events:

this.$bus.on("parameterName",function(value){
  console.log(value)
});
Copy after login

Unbind the event when the component is destroyed:

destroyed:function(){
  this.$bus.off("parameterName")
}
Copy after login

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 of this Website
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

Hot Article Tags

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

How to use echarts in vue How to use echarts in vue May 09, 2024 pm 04:24 PM

How to use echarts in vue

The role of export default in vue The role of export default in vue May 09, 2024 pm 06:48 PM

The role of export default in vue

How to use map function in vue How to use map function in vue May 09, 2024 pm 06:54 PM

How to use map function in vue

The difference between event and $event in vue The difference between event and $event in vue May 08, 2024 pm 04:42 PM

The difference between event and $event in vue

The difference between export and export default in vue The difference between export and export default in vue May 08, 2024 pm 05:27 PM

The difference between export and export default in vue

The role of onmounted in vue The role of onmounted in vue May 09, 2024 pm 02:51 PM

The role of onmounted in vue

Onmounted in vue corresponds to which life cycle of react Onmounted in vue corresponds to which life cycle of react May 09, 2024 pm 01:42 PM

Onmounted in vue corresponds to which life cycle of react

What are hooks in vue What are hooks in vue May 09, 2024 pm 06:33 PM

What are hooks in vue

See all articles