标签:另一个 组件通信 收信 bof str rom this 通信 efault
import Vue from ‘vue‘
const bus = new Vue()
export default bus
import bus from ‘@/main/bus‘
bus.$emit(‘message‘, ‘hello‘)
import bus from ‘@/main/bus‘
methods: {
test(e) {
console.log(e)
}
}
mounted() {
bus.$on(‘message‘, this.test)
}
boforeDestroy() {
bus.$off(‘message‘, this.test)
}
import bus from ‘@/main/bus‘
mounted () {
bus.$on(‘testA‘, this.testA)
},
methods: {
testA () {
console.log(‘由A组件调用‘)
}
}
import bus from ‘@/utils/bus‘
mounted () {
bus.$emit(‘testA‘)
}
boforeDestroy() {
bus.$off(‘testA‘, this.testA)
}
标签:另一个 组件通信 收信 bof str rom this 通信 efault
原文地址:https://www.cnblogs.com/niuzijie/p/13373292.html