报错: Cannot read properties of undefined (reading ‘$on‘)

报错截图:

报错: Cannot read properties of undefined (reading ‘$on‘)_第1张图片

报错原因:

在注册全局事件总线的时候,我误将beforeCreate钩子写成了mounted,导致找了一下午……

new Vue({
  el:'#app',
  render: h => h(App),
  beforeCreate(){
    Vue.prototype.$bus=this
  }
})

顺便说一下,我上次写Vue的原型链时写成了:

this.prototype.$bus=this,也导致找了一下午……大家引以为戒 o(╥﹏╥)o

一定要写成Vue.prototype.$bus=this,而且由于Vue是在main.js引入的,所以牢记全局事件总线在main.js注册~~❀❀

以及不要将beforeCreate写成beforeCreated o(╥﹏╥)o

你可能感兴趣的:(前端,vue.js,javascript,前端)