vue-obs-eventbus

vue eventbus with devtools
320 4
Install
npm install vue-obs-eventbus
Latest Version:0.0.15
Vue:2 · 3
License:MIT
Last Updated:Dec 28, 2022
Links: GitHub  ·  npm
Maintainer: poyoho

vue-obs-eventbus

vue devtool listen on eventbus.

getting start

If you are using Vue 2, you need to install a plugin and inject the created eventbus at the root of the app:

import Vue from 'vue'
import App from './App.vue'
import { createEventBusDevToolsPlugin, EventBusDevToolsVue2Plugin } from 'vue-obs-eventbus'

Vue.use(EventBusDevToolsVue2Plugin)

new Vue({
  eventbus: createEventBusDevToolsPlugin(),
  render: h => h(App),
})

If you are using Vue 3, you need to create a eventbus instance and pass it to the app as a plugin:

import { createApp } from 'vue'
import App from './App.vue'
import { createEventBusDevToolsPlugin } from "vue-obs-eventbus"

const eventbus = createEventBusDevToolsPlugin()

createApp(App).use(eventbus).mount('#app')

create a eventbus

Define the event types into createEventBus.

import { createEventBus } from 'vue-obs-eventbus'

export const eventbus = createEventBus<{
  'hello': number
}>('default')

you can use the eventbus by direct.

import { eventbus } from "./eventbus"

eventbus.emit('hello', 1)

eventbus.on('hello', (data) => {
  console.log(data)
})

you also can hoist the eventbus into vue prototype.

// vue2
Vue.prototype.$eventBus = eventBus

// vue3
app.config.globalProperties.$eventBus = eventBus

and the use it by this in options api.

export default {
  methods: {
    emit(event, data) {
      this.$eventbus.emit(event, data)
    }
  }
}

after use the eventbus, vue-obs-eventbus will collect the emit event and log it in the vue-devtools

devtools

Related Packages

@tanstack/vue-devtools

TanStack Devtools is a set of tools for building advanced devtools for your Vue...

100,583 507
@devframes/vite

Vite plugin for mounting a devframe inside any Vite-based host (Astro, SolidStar...

1,088,260 667
@devframes/nuxt

Nuxt module that exposes a Nuxt app as a devframe client.

12,385 670
nuxt-mailpit

Nuxt 3 devtools integration for Mailpit.

8,380 3
@nguyenshort/vue3-mitt

Vue3 eventbus using mitt

5,762 3

Version History

Version Released Vue License
0.0.15 ^2.6.14 || ^3.2.0 MIT
0.0.14 ^2.6.14 || ^3.2.0 MIT
0.0.13 ^2.6.14 || ^3.2.0 MIT
0.0.12 ^2.6.14 || ^3.2.0 MIT
0.0.11 ^2.6.14 || ^3.2.0 MIT