1.0.6 • Published 4 months ago

nuxt-event-bus v1.0.6

Weekly downloads
-
License
MIT
Repository
github
Last release
4 months ago

Nuxt3 Event-Bus

A Nuxt3 plugin which adds a global event bus to your nuxt-project.

Installation

Using npm

npm i nuxt-event-bus --save

Setup

Add 'nuxt-event-bus' to the modules array inside nuxt.config.ts.

Usage

Inside your Components e.g. App.vue

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

Interface

This Plugin provides the following interface
this.$event.$on(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.$event.$off(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.$event.$emit(eventName, params):

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

License

MIT

1.0.6

4 months ago

1.0.4

9 months ago

1.0.3

9 months ago

1.0.1

9 months ago