vue实现登录验证的代码

2023-10-27,,

这篇文章运用了实例代码展示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);
  }

关于vue实现登录验证的代码就分享到这里了,希望以上内容可以对大家有一定的帮助,可以学到更多知识。如果觉得文章不错,可以把它分享出去让更多的人看到。

《vue实现登录验证的代码.doc》

下载本文的Word格式文档,以方便收藏与打印。