vue 模拟登录验证并跳转当前页面

主要代码

router.ts


router.beforeEach((to, from, next) => {
  console.log(to, from)
  if (to.name !== "login") {
    if (sessionStorage.getItem("session")) {
      next()
    } else {
      next('/login?form=' + to.fullPath);

    }
  }
  next();
})

login.vue:

submitForm(value) {//登陆方法

    //...省略验证和存session 一般放在sessionStorage里面
    let fromUrl = unescape(location.search.split("=")[1]);
    this.$router.push(fromUrl);
  }

猜你喜欢

转载自blog.51cto.com/13496570/2431500