我正在尝试通过 访问 vue-router 中的会话this.a.app,但它弹出 1 个错误。在我调试之后,我发现它this是未定义的。这是我用来显示的代码this。
我曾尝试使用function(to, from, next) {...}而不是 es6 语法,但this仍然未定义。
router.beforeEach((to, from, next) => {
if (!to.meta.isPublic){
// eslint-disable-next-line
console.log(this)
}
next()
})
Run Code Online (Sandbox Code Playgroud)
是否需要进行任何配置才能this在 vue-router 中访问?