vue-super-eventbus
v2.4.1
Published
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.
Readme
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-eventbusUsage
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.
}