vue全局路由从vuex里面取值判断

请教一下,我登陆首页的时候需要根据Id去判断显示的页面,但是id是从vueX里面取出来的,直接用一直是undefined,想知道要怎样能娶到Vuex里的值实现需求呢?


 {
    path: '/401',
    component: () => import('@/views/error/401'),
    hidden: true
  },
  {
    path: '/calControl',
    component: () => import('@/view/calControl/index'),
    hidden: true,
  },
  {
    path: '',
    component: Layout,
    redirect: 'index',
        
    children: [
      {
        path: 'index',
        component: () => import('@/view/index'),
        name: 'Index',
        meta: { title: '首页', icon: 'dashboard', affix: true },
        beforeEnter:function(to,form,next){
          console.log(to,form)
                    if(this.userRole.find((item) => item.Id == "15")){
          if(form.path == '/login'){
            next('/calControl')
          }else{
            next()
          }
                    }else{
                        next()
                    }
        }
      }
    ]
  },

组件连接 store 然后this.$store应该能拿到吧 。如果在 路由文件里 需要把 store挂载到 vue实例上

建议在首页监听路由,(一般的 不建议在路由表有其他逻辑,除非你的其他逻辑逻辑写在导航守卫钩子。)