vue报错 Error in mounted hook “TypeError Cannot read properties of undefined (reading ‘$on‘)“
vue报错 Error in mounted hook “TypeError Cannot read properties of undefined (reading ‘$on‘)“
·
问题描述:
控制台报错
Error in mounted hook “TypeError Cannot read properties of undefined (reading ‘$on‘)“
1、先排除已经写完了谁要传值,即
this.$bus.$emit('getIndex',this.currentIndex);
2、也写了谁接收,即
mounted(){
//全局事件总线,获取兄弟组件传递过来的索引值
this.$bus.$on('getIndex',(index)=>{
console.log(index);
})
},
3、那么就在main.js
里加入代码
// event Bus 用于无关系组件间的通信。
Vue.prototype.$bus = new Vue()
更多推荐
已为社区贡献3条内容
所有评论(0)