是否可以从路由器调用vuex getter?我需要检查beforeach钩子中的一个布尔变量的状态:
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()
}
})如何获取和检查从存储派生的变量?
非常感谢!
发布于 2016-04-19 06:36:53
这里有一个关于这方面的讨论: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
https://stackoverflow.com/questions/36705282
复制相似问题