main.ts
Vue.prototype.$bus = new Vue()
xxx.vue
import CombinedVueInstance from 'vue'
export default class XXX extends Vue {
$bus!: CombinedVueInstance
emitHandle() {
this.$bus.$emit('test', 'hello')
}
}
yyy.vue
import CombinedVueInstance from 'vue'
export default class YYY extends Vue {
$bus!: CombinedVueInstance
mounted() {
this.$bus.$on('test', (msg) => {
console.log(msg)
})
}
}
原创文章,作者:506227337,如若转载,请注明出处:https://blog.ytso.com/tech/pnotes/269427.html