[Vue warn]: Error in mounted hook: "TypeError: Cannot read properties of undefined (reading 'init')
时间: 2023-10-15 10:25:16 浏览: 182
vue.js页面加载执行created,mounted的先后顺序说明
这个错误是在Vue的mounted钩子函数中出现的,具体的错误信息是"TypeError: Cannot read properties of undefined (reading 'init')". 这个错误通常是由于访问了一个未定义的属性或方法引起的。根据引用的信息,你可能遇到了类似的问题,即无法读取一个未定义的属性$emit。为了解决这个问题,你可以按照引用中的建议,在main.js文件中加入如下代码:
```
Vue.prototype.$bus = new Vue()
```
这样就可以创建一个事件总线(event bus),用于在无关联的组件之间进行通信。然后,你可以按照引用中的方法,将emit函数的调用稍作修改:
```
this.$nextTick(function () {
// DOM 现在更新了
this.$bus.$emit('msg', route)
})
```
这样修改之后,应该就能够解决这个错误了。<span class="em">1</span><span class="em">2</span><span class="em">3</span>
#### 引用[.reference_title]
- *1* *3* [[Vue warn]: Error in created hook: “TypeError: Cannot read properties of undefined (reading ‘$on...](https://blog.csdn.net/Youweretrouble/article/details/129189556)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_1"}}] [.reference_item style="max-width: 50%"]
- *2* [[Vue warn]: Error in mounted hook: “TypeError: Cannot read properties of undefined (reading ‘$on...](https://blog.csdn.net/qq_45803094/article/details/126476879)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_1"}}] [.reference_item style="max-width: 50%"]
[ .reference_list ]
阅读全文