1.0.4 • Published 4 years ago

darkfriend-vue-eventbus v1.0.4

Weekly downloads
8
License
MIT
Repository
github
Last release
4 years ago

Vue eventBus

Easy eventbus for vue.js.

How install

npm i darkfriend-vue-eventbus -S

How use

global init
import Vue from 'vue';
import eventBus from 'darkfriend-vue-eventbus';

Vue.use(eventBus);

new Vue({
    mounted() {
        // listen event
        this.eventBus.$on('eventName', (eventData) => {
            console.log(eventData); // {param1: 'value1', param2: 'value2'}
        });

        // send event with args
        let args = {param1: 'value1', param2: 'value2'};
        this.eventBus.$emit('eventName', args);
    }
});

The use eventBus component options.

new Vue({
  eventBus: {
    eventName(eventData){
       console.log(eventData)    
    }
  }  
})

local init
import {eventBus} from 'darkfriend-vue-eventbus';

// send
let args = {param1: 'value1', param2: 'value2'};
eventBus.$emit('eventName', args);

// listen
eventBus.$on('eventName', (eventData) => {
    console.log(eventData);
});

Methods

MethodParamsDescriptionDocs
eventBus.$emitevent, payloadEmit the event with the given payload.vm.$emit
eventBus.$onevent, callbackListen for the event with the given callback.vm.$on
eventBus.$offevent, callbackRemove event listener(s) for the eventvm.$off
eventBus.$onceevent, callbackListen for a custom event, but only oncevm.$once
1.0.4

4 years ago

1.0.2

4 years ago

1.0.3

4 years ago

1.0.1

4 years ago