登录 路由拦截
- Cookie
router.beforeEach((to,from,next)=>{
store.commit('setToken',Cookie.get('token'))
if(store.state.token){
store.commit('changIsSignIn',1)
}
if(to.meta.requireAuth){
if(store.state.token){
next()
}else{
next({path:'/login'})
}
}else{
next()
}
})
- sessionStorage
//路由导航守卫
router.beforeEach((to,from,next)=>{
const token=window.sessionStorage.getItem('token');
if(to.path =='/login'){
next();
}else{
if(token){
next();
}else{
next('login');
}
}
})
本文来自博客园,作者:zjxgdq,转载请注明原文链接:https://www.cnblogs.com/zjxzhj/p/14886016.html