const router = new VueRouter({
mode:'history',
routes
});
router.beforeEach((to, from, next) => {
if (to.meta.requiresAuth) {
console.log(Store.state.AuthUser);
/*
* 此时 AuthUser.authenticated 为true
* {__ob__: Observer}
authenticated:true
email:"[email protected]"
name:"12345"
*
* */
console.log(Store.state.AuthUser.authenticated);
/*
此时 AuthUser.authenticated 为false
*/
if (Store.state.AuthUser.authenticated || JWTToken.getToken()) {
return next();
} else {
return next({ name : 'confirm' });
}
}
if (to.meta.requiresGuest) {
if (Store.state.authenticated || JWTToken.getToken()) {
return next({ name : 'home' });
} else {
return next();
}
}
next();
});
export default router;
Store.state.AuthUser 有值
Store.state.AuthUser.authenticated 始终为false 不知道是什么原因 @JellyBool 有遇到这个问题吗?