【发布时间】:2020-08-20 02:53:59
【问题描述】:
我想在路由器中获取日期表单获取器。 我的商店中有 2 个模块:
export default function (/* { ssrContext } */) {
const Store = new Vuex.Store({
modules: {
customers,
auth
},
namespaced: true,
strict: process.env.DEV
})
return Store
}
这是我的 auth/index.js
import state from "./state";
import * as getters from "./getters"
import * as mutations from "./mutations"
import * as actions from "./actions"
export default {
namespaced: true,
state,
mutations,
actions,
getters
}
我想检查我的用户是否经过身份验证,所以在转到组件之前我想检查它。
{
path: '',
component: () => import('pages/Index.vue'),
beforeEnter: ifAuthenticated()
},
现在在 router/index.js 我声明我的函数
export function ifAuthenticated(to, from, next){
console.log(store.auth); //undefined
if (store.auth.getters.isAuthenticated) {
next();
return;
}
next("/login");
};
我如何调用我的 getter 来返回值,或者我如何调用我的 store 来获取 auth 模块?
【问题讨论】:
-
console.log(this.$store.auth) 怎么样?
-
打印未定义
-
console.log(this.$store)?
-
同样的结果
-
您应该在可以访问商店的地方动态添加此路线并定义如下路线:
beforeEnter: (to, from, next) => { ifAuthenticated(to, from ,next, this.store) // add fourth param 'store' to the ifAuthenticated }
标签: vue.js vuex vue-router quasar-framework quasar