vue路由守卫

//在Home里面写
if (this.current == "laowang" && this.password == "laowang666") {
        //若账号或密码正确,则在缓存里面存一个isLogin值为1
        localStorage.setItem("isLogin", "1");
        this.$router.push("/Dashboard");
      }
      
//在router--index.js里面写以下内容判断是否登录
const router = new VueRouter({ routes });
router.beforeEach((to, from, next) => {
	//若能获取缓存里面的isLogin则说明已经登陆了,可以成功跳转
  if (localStorage.getItem("isLogin") == "1") {
    next();
  } else {
    if (to.name == "Home") {
      next();
    } else {
      next({ name: "Home" });
      alert("请先登录");
      next();
    }
  }
});
export default router;

上一篇:公有云服务对比IDC服务,有哪些优势?


下一篇:idc机房加固如何让建筑物满足机房使用要求