查看: 37|回复: 0

vue 路由守卫

[复制链接]

1

主题

0

回帖

0

积分

积极分子

金币
0
阅读权限
220
精华
0
威望
0
贡献
0
在线时间
0 小时
注册时间
2011-6-12
发表于 2020-9-18 11:27:00 | 显示全部楼层 |阅读模式

1.登录成功后

.then(res => {
// console.log(res);
// 检验成功 设置登录状态并且跳转到/
localStorage.setItem("ele_login", true);
this.$router.push("/");

 

}

 

router.js里面

// 路由守卫
router.beforeEach((to, from, next) => {
const isLogin = localStorage.ele_login ? true : false;
if (to.path == '/login') {
next();
} else {
// 是否在登录状态下
isLogin ? next() : next('/login');
}
});



来源:https://www.cnblogs.com/xzhce/p/13690248.html
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

相关侵权、举报、投诉及建议等,请发 E-mail:qiongdian@foxmail.com

Powered by Discuz! X5.0 © 2001-2026 Discuz! Team.

在本版发帖返回顶部