Cannot read properties of undefined (reading '$on')"
时间: 2023-11-14 11:12:52 浏览: 59
这个错误通常是因为在使用Vue的事件总线时,没有正确地注册或者没有正确地引入Vue。'$on'是Vue中用于监听事件的方法,如果出现了Cannot read properties of undefined (reading '$on')的错误,说明代码中使用了'$on'方法,但是Vue并没有正确地被引入或者注册。解决方法是确保Vue已经被正确地引入,并且在Vue实例中正确地注册了事件总线。可以在Vue实例中使用beforeCreate钩子来注册事件总线,例如:
```
new Vue({
beforeCreate() {
this.$bus = new Vue();
},
// 其他配置
})
```
这样就可以在Vue实例中使用事件总线了。如果还是出现了Cannot read properties of undefined (reading '$on')的错误,可以检查代码中是否正确地使用了'$on'方法,或者是否在正确的Vue实例中使用了事件总线。
相关问题
Cannot read properties of undefined (reading '$on') TypeError: Cannot read properties of undefined (reading '$on')
这个错误通常是因为你在使用Vue的事件总线时没有正确地创建它。根据引用中提供的解决方法,你需要在main.js中添加代码 `Vue.prototype.$bus = new Vue()` 来创建一个事件总线。如果你已经添加了这行代码,那么可能是因为你在使用事件总线之前没有正确地引入它。请确保你在使用事件总线之前已经正确地引入了它。
cannot read properties of undefined reading matched
这个错误"Cannot read properties of undefined (reading 'matched')"通常是由于访问了一个未定义的属性而引起的。根据引用,这个错误可能是在访问一个未定义的'matched'属性时出现的。
根据引用,解决这个问题的方法是检查导入的router实例对象的属性名是否正确。确保在实例化对象中的属性名和值名一致。
另外,根据引用,一种解决方法是将导入的Router改成小写的router,并且将所有相关的Router都改成小写。
综上所述,如果你遇到了"cannot read properties of undefined reading matched"错误,你可以检查一下导入的对象属性名是否正确,并将相关的属性名改成小写,以解决这个问题。<span class="em">1</span><span class="em">2</span><span class="em">3</span>
#### 引用[.reference_title]
- *1* *3* [TypeError: Cannot read properties of undefined (reading ‘matched‘)“错误](https://blog.csdn.net/xuehua_zhx/article/details/122112017)[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_2"}}] [.reference_item style="max-width: 50%"]
- *2* [解决问题:Cannot read properties of undefined (reading ‘matched‘)“报错](https://blog.csdn.net/qq_55761697/article/details/125402362)[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_2"}}] [.reference_item style="max-width: 50%"]
[ .reference_list ]