Vue.js vue中的KeyClope global

Vue.js vue中的KeyClope global,vue.js,router,Vue.js,Router,据我所知。下面的配置函数应该允许全局访问我的KeyClope实例 Main.js myApp.config.globalProperties.$keycloak = keycloak; 它在任何地方都能正常工作,但在router.js文件中却没有 router.js console.log($keycloak.authenticated); 返回未定义的。请告诉我该怎么做 router.js如下所示: const preventRoutes = { beforeEnter: (to,

据我所知。下面的配置函数应该允许全局访问我的KeyClope实例

Main.js
myApp.config.globalProperties.$keycloak = keycloak; 
它在任何地方都能正常工作,但在router.js文件中却没有

router.js
console.log($keycloak.authenticated);
返回未定义的。请告诉我该怎么做

router.js如下所示:


const preventRoutes = {
  beforeEnter: (to, from, next) => {
    console.log(store.getters.getLoginState);
    // console.log(this.$keycloak.authenticated);
    if (store.getters.getLoginState === "true") {

      next();
    } else {

      
      next("/");
    }

  }

}


const routes = [
{
    path: '/dashboard',
    name: 'Dashboard',
    component: dashboard,
    ...preventRoutes,

  },

]


const router = createRouter({
  mode: "history",
  history: createWebHistory(process.env.BASE_URL),
  routes
})

export default router




显示该console.log的上下文。你在哪里调用它?我在router.js文件中调用它。在那里我有我所有的路线。试着把它改成“this.$keydave”。不。仍然(无法读取未定义的属性“$keydape”)显示router.js的更多代码