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";
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.
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...
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...
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...
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...
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...
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...
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 ...
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 ...
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...