vue-epic-bus

Bus plugin for vue.js
6,239 5
Install
npm install vue-epic-bus
Latest Version:0.1.5
Vue:2
Last Updated:Jan 3, 2023
Links: GitHub  ·  npm
Maintainer: asva

vue-epic-bus

Emit and subscribe to global bus from your components

Gist

  • Minimal boilerplate.
  • Vue flavor.
  • Can't be used outside of vue components (intended).
  • No memory leaks.

Installation

  • Add to dependencies:
yarn add vue-epic-bus
// or
npm i vue-epic-bus
  • Install plugin
// main.js
import Vue from 'vue'
import {BusPlugin} from 'vue-epic-bus'
Vue.use(BusPlugin)

Usage

Subscribe:

<script>
export default {
  subs: {
    productUpdated (id) {
      console.log('Product updated', id)
    }
  },
}
</script>

Emit:

<script>
export default {
  methods: {
    productUpdated (id) {
      this.$cast('updated', id)
    }
  },
}
</script>

$cast could be used from template.

<button @click="$cast('updated', id)">Update</button>

If you're unhappy with default word choice for $cast and subs you can change it via plugin options:

Vue.use(BusPlugin, {
  optionGroupName: 'subs',
  broadcastName: '$cast',
})

Version History

Version Released Vue License
0.1.5 ^2.0
0.1.4 ^2.0
0.1.3 ^2.0
0.1.2 ^2.0
0.1.1 ^2.0
Pre-releases (1)
Version Released Vue License
0.1.3-alpha.0 ^2.0