0.9.3 • Published 2 years ago

nuxt-bus v0.9.3

Weekly downloads
-
License
ISC
Repository
github
Last release
2 years ago

nuxt-bus

FNiX.iR

Event Bus for Nuxt.JS v3

Install

npm i nuxt-bus
// ~/plugins/bus.ts
import bus from 'nuxt-bus'
// or any name you want -> $bus
export default defineNuxtPlugin(() => ({ provide: { bus } }))

Usage

// listener
this.$bus.on('event', ($event) => { /* your code with $event data */ })
// emitter
this.$bus.emit('event', eventData)

You can get all handlers of all types set in project .all

And you can use .off method to stop listening to an event, or just a specific handler in it

this.$bus.all
//
this.$bus.off('event')
//
this.$bus.on('event', handler)
this.$bus.off('event', handler)