TypeError: Cannot read property '$emit' of null Vuejs Router

TypeError: Cannot read property '$emit' of null Vuejs Router

我有这样的路由器

{
          path: 'user',
          redirect: '/user',
          name: 'user',
          component: {
            render(c) {
              return c('router-view', {
                on: {
                  showLoading: function (val) {
                    this.$emit('showLoading', val)
                  }
                }
              })
            }
          },

当运行那个路由器出现错误时

"[Vue warn]: Error in event handler for "showLoading": "TypeError: Cannot read property '$emit' of null"

。 当我用谷歌搜索时,似乎我无法在路由器内部使用 this.$emit 。我想发出事件 'showLoading',可以吗?

尝试使用未定义自己的箭头函数 this

showLoading: val => {
   this.$emit('showLoading', val)
}

Arrow function expressions