---main.js文件中全局挂载bus
new Vue({
el: '#app',
router,
store,
render: h => h(App),
// beforeCreate中模板未解析,且this是vm
beforeCreate() {
Vue.prototype.$bus = this //安装全局事件总线
}
})
---传递数据的组件中-触发事件
this.$bus.$emit('fileUploadSuccess', annexList)
---接收并销毁mounted
this.$bus.$on('fileUploadSuccess', annexList => {
self.$parent.annexList = [].concat(annexList)
// 销毁$on监听的事件
this.$bus.$off('fileUploadSuccess')
})