tags: Vue javascript
Communication within the component is also transmitted data
The brothers component passes the value, the grandchildren component pass the value, and the component is called when all called components should be in response to some functions.
New JS file Eventbus.js
Content is a Vue instance
import Vue from 'vue'
export default new Vue()
If the global call, in main.js
import eventBus from './util/eventBus'
Vue.prototype.$bus = eventBus
Local call, introduce this file directly in the calling component
import bus from './../../util/eventBus.js'
How to use, pass
this.$bus.$emit('mapId', this.mapId)
Here, a data called Mapid is delivered globally, and his content is this.mapid.
Received at the use, Target is the content of this.mapid
this.$bus.$on('mapId', target=>{
console.log(target)
})
initialization Suppose you have two Vue pages that need to communicate: A and B. The A page binds a click event to the button, and sends a message to notify the B page. //Use emit to distribute in A U...
Some scenes use the Eventbus bus to make the code much simple. Step 1: Write an Eventbus class Step 2: Place the event bus in Vue, find the main.js file to join the following code The third step: is t...
1. Introduction of the event bus Vue components are very common with parent sub-component communication, brothers component communications. The parent subcomponent communication is very simple, and th...
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...
Vuex to use 1. Introduction and Installation 2. Configure 3. Registration 4. In the assembly 1. Introduction and Installation EventBus: Also known as the event bus. EventBus can be used in the Vue as ...
1. Guide package 2. Add confusion The obfuscation rules are as follows 3. The first activity 4. The second activity 5. Simple functions are achieved...
Preface First of all, let's talk about the event bus, its role: in order to simplify and higher quality communication between Activity, Fragment, Thread and Service, etc., to solve the high coupling b...