【vue】$bus 跨组件调用方法

2023-12-20

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')
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

【vue】$bus 跨组件调用方法 的相关文章