new Vue({
el:'#app',
render: h => h(App),
beforeCreate() {
Vue.prototype.$bus = this
},
});
Vue.prototype.$bus = new Vue({
el:'#app',
render: h => h(App),
});
第一种是教程里面的第二种是我自己想的,两种都能在vue的对象里面看见$bus这个对象,但是我这种在教程代码里就报错
mounted() {
console.log('School',this)
this.$bus.$on('hello',(data)=>{
console.log('我是School组件,收到了数据',data)
})
},
beforeDestroy() {
this.$bus.$off('hello')
},