【发布时间】:2016-08-10 20:35:46
【问题描述】:
是否可以从路由器调用 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()
}
})
非常感谢!
【问题讨论】:
-
只需导入存储路由器文件 "import store from '../store'" 并返回存储值 "return store.getters" 但是如果你想访问存储的值路由,最好使用 vue-router-sync 包
标签: reactive-programming vue.js vue-router vue-component