1.0.1 • Published 4 years ago

vue-custom-eventbus v1.0.1

Weekly downloads
-
License
ISC
Repository
-
Last release
4 years ago

在 Vue 项目中使用 EventBus 拥有生命周期,不用再去手动销毁 参考文章:让在 Vue 中使用的 EventBus 也有生命周期 ##使用 npm install vue-custom-eventbus

import eventBus from 'vue-custom-eventbus';
Vue.use(eventBus);

##组件中使用

 created () {
   let text = Array(1000000).fill('xxx').join(',')
   this.$eventBus.$on('MY_EVENT', (...args) => {
     // todo something
   }, this) // 注意第三个参数要传this 否则需要手动销毁事件
 },
 click () {
    this.$eventBus.$emit('MY_EVENT', '这是$emit参数')
 }