bus 跨组件调用方法

1、新建bus.js

import Vue from 'vue'

// 使用 Event Bus
const bus = new Vue()

export default bus

2、main.js引用

import bus from '@/libs/bus'
Vue.prototype.$bus = bus

3、被调用组件 this.getList()方法

 created() {
    this.$nextTick(()=>{
      this.$bus.$on("getList", () => {this.getList()})
    })
  },

4、调用组件

this.$bus.$emit('getList')


版权声明:本文为jiangjiang_ing原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。