是否可以从路由器调用vuex getter? 我需要检查来自beforeach hook的布尔变量的状态:
router.beforeEach(function ({ to, next }) {
if (to.path !== '/login') {
// return a Promise that resolves to true or false
return the-needed-variable-from-store;
} else {
next()
}
})
非常感谢!
答案 0 :(得分:0)
这里有一个讨论:https://github.com/vuejs/vuex-router-sync/issues/3#issuecomment-200192468
我能够以相当荒谬的方式访问变量:
router.beforeEach((transition)=>{
if(transition.to.auth){
if(!transition.to.router.app.$store.state.auth.authorized){
transition.abort()
router.go({path:"/"})
}
}
transition.next()
});
因此,在您的情况下,它可能看起来像to.router.app.$store.state