Let Vue.js support global events
TypeScript support already (actually this plugin is written by TypeScript)
$ npm i vue-geventbus -S
# or
$ yarn add vue-geventbus -S
- Install this Vue plugin
import VueEventBus from "vue-geventbus";
Vue.use(VueEventBus);
- use Global Event function
just like
Vue.$on
,Vue.$emit
, but this plugin handle global event below is the table
Vue Api | VueEventBus Api |
---|---|
$on | $gon |
$once | $gonce |
$emit | $gemit |
$off | $goff |
More see: https://cn.vuejs.org/v2/api/#vm-on