Vue中央事件总线插件

vue-bus.js代码vue

import Vue from 'vue'
const Bus = new Vue({
  methods: {
    emit(event, ...args) {
      this.$emit(event, ...args)
    },
    on(event, callback) {
      this.$on(event, callback)
    },
    off(event, callback) {
      this.$off(event, callback)
    }
  }
})
Vue.prototype.$bus = Bus

export default Bus

复制代码

main.js引入bash

import Bus from './vue-bus.js'
Vue.use(Bus)
复制代码
相关文章
相关标签/搜索