1.在mian.js内声明eventBus
window.eventBus = new Vue();
2.在组件中使用:
在某一组件内赋值:
eventBus.$emit('bus','aaa');
在其他组件内都可以使用: 越早接收越好,最好在created里面
eventBus.$on('bus',param=>{
console.log(param);// aaa
}
window.eventBus = new Vue();
在某一组件内赋值:
eventBus.$emit('bus','aaa');
在其他组件内都可以使用: 越早接收越好,最好在created里面
eventBus.$on('bus',param=>{
console.log(param);// aaa
}