Skip to content

F-NiX/nuxt-bus

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

nuxt-bus

FNiX.iR

Event Bus for Nuxt.JS v3

dist: less than 300 bytes!

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)

Note: this is available inside vue option methods, if you are using <script setup> mode, you may need useNuxtApp to get $bus:

const { $bus } = useNuxtApp()
// $bus.on ...
// $bus.emit ...

About

Event Bus for Nuxt.JS v3

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published