xygahs0801 / vue-super-eventbus

Vue eventbus enhancements to support automatic destruction and other many features.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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.
}

About

Vue eventbus enhancements to support automatic destruction and other many features.


Languages

Language:JavaScript 100.0%