vue ---- Event Bus (eventBus)

Vue event bus (eventBus)

EventBus event bus for communication between the two components,
is used to establish eventBus.js file as follows:

import Vue from 'vue'
export default new Vue();

Import respectively in two components need to communicate in

  import bus from "common/utils/eventBus";
  • Then can emit, on communication: as follows:
A transmitting component
bus.$emit('SUBMITSEARCH_PEOPLE',this.searchContent)
Another component of the received
bus.$on('SUBMITSEARCH_PEOPLE', function (data) {...}

Between the three types:

1、vm.$on( event, callback )

Custom event listeners on the current instance. Events can. $ Emit triggered by vm. The callback function will receive all incoming events triggered additional function parameters.

2、vm.$emit( event, […args] )

Trigger event on the current instance. Additional parameters are passed to the callback listener, if no parameters in the form vm. $ Emit (event)

3、vm.$off( [event, callback] )

Remove custom event listeners.

  • If no parameters, then remove all the event listeners;
  • If only event, then remove all the event listeners;
  • If both events and callbacks, only remove this callback listener.

Intelligent Recommendation

Vue Transfer Event Bus Eventbus

There is a simple method between components in Vue. Create Even.js (name your own) The following is the code created in the JS file. There are two components of A, B, and JS that needs to be created i...

Vue event bus (EventBus) with caution

Usually suitable for brothers component value It is best to plan the scope of function -Profin the range of instance control (different instances in different areas) -An the scope of control space con...

Vue event bus (EVENTBUS) learning

1. 1. Background We know that there are many ways to transfer data between Vue components, such as:Father -child component communication,Intergenerational component communication,Routing,vuexWait, but...

The concept, use and attention of vue event bus EventBus

vue event bus Preface text Introduction to EventBus Use of EventBus One, initialization Two, send events to EventBus Three, receive events Fourth, remove the monitoring event Concluding remarks Prefac...

More Recommendation

Use the central event bus eventBus in vue

Use the central event bus eventBus in vue Prepare to create files: router/index.js : App.vue : src/utils/eventBus.js : src/components/sky.vue : src/components/news.vue : src/views/About.vue Click on t...

Talk about the event bus mechanism in vue-EventBus

Vue event bus mechanism-EventBus The background of the event bus The core part in vue is the component, and the communication between components is the top priority. Communication is divided into pare...

Vue Development Central Event Bus Eventbus

  Use background:   In Vue development, a large number of components are encountered, and VUE has a corresponding solution for different situations. For example, the parent component can use the ...

Vue implementation global Eventbus (global event bus)

Basic knowledge: There are three events on VUE prototypes: $ N (), $ EMIT (), $ OFF () The prototype object of the component object is a VM object: the component object can directly access the method ...

Vue in the event bus (Eventbus) detailed and used

Portal: Vue ion assembly to the parent components and .sync modifier Portal: Vue State Manager (Vuex) Detailed and Application Scene Portal: Vue $ Attrs, $ Listeners More 1 Introduction Frequently ava...

Copyright  DMCA © 2018-2026 - All Rights Reserved - www.programmersought.com  User Notice

Top