npm.io
2.4.1 • Published 6 years ago

vue-super-eventbus

Licence
ISC
Version
2.4.1
Deps
0
Size
6 kB
Vulns
0
Weekly
0
Stars
3

vue-super-eventbus

An enhanced component of Vue event bus can be automatically destroyed without manual cancellation of subscription events, modularization, immutability of event data and many other features.

Install

npm i --save vue-super-eventbus

Usage

On Vue entry
import EventBus from "vue-super-eventbus"
Vue.use(EventBus)
In Vue component
// Recommend
on:{
  event1(data){
    // handle data
    console.log(data)
  },
  event2(data){
    // handle data
    console.log(data)
  }
},
// Or
created() {
  this.$bus.on(this, "event1", data => {
    // handle data
    console.log(data);
  });
  this.$bus.on(this, "event2", data => {
    // handle data
    console.log(data);
  });
},
In other Vue component
created() {
  this.$bus
    .emit("event1", 'test message')
    .emit("event2", { message: "test json message" });
}
beforeDestroy() {
  // No need to off the event, The lib take care of this for you.
}

Keywords