Vue event bus, Eventbus use

tags: Vue  javascript  

purpose of usage

Communication within the component is also transmitted data

Scope of application

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.

Use example

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)
})

Intelligent Recommendation

Vue event bus (EventBus) introduction

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

Vue Set Event Bus Eventbus

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

What is Vue Event Bus (Eventbus)

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

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

More Recommendation

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

Vue.js use in the event of bus EventBus

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

Simple use of EventBus event bus

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

Android event bus-the use of EventBus

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

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

Top