1.0.1 • Published 3 years ago

@carbdrox/vue-event-bus v1.0.1

Weekly downloads
-
License
MIT
Repository
github
Last release
3 years ago

Vue.Js Event-Bus

A Vue.Js plugin which adds a global event bus to your vue-project.

Installation

Using npm

npm i @carbdrox/vue-event-bus --save

Setup

Normally done inside main.js

import VueEventBus from "@carbdrox/vue-event-bus";

Vue.use(VueEventBus);

Usage

Inside your Components e.g. App.vue

export default {
    created() {
        this.$addListener('event', () => {
            console.log('event Fired!')
        });
    },
    methods: {
        fireEvent() {
            this.$emitEvent('event');
        }
    }
}

Interface

This Plugin provides the following interface
this.$addListener(eventName, listener, amount):

ParameterRequiredDescription
eventNameyesThe name of the event to listen for.
listeneryesThe function that will be executed when the event is fired.
amountnoThe number of times the listener should be executed. (empty or -1 for no limit)

this.$removeListener(eventName, listener):

ParameterRequiredDescription
eventNamenoThe name of the event to remove. If no eventName specified, all events will be deleted
listenernoThe function of the event to be deleted. If no function is specified, all functions of the specified event will be deleted

this.$emitEvent(eventName, params):

ParameterRequiredDescription
eventNameyesThe name of the event to be fired.
paramsnoThe parameter to be passed to the event. If multiple parameters are required, they must be passed as object.

License

MIT