码迷,mamicode.com
首页 > 其他好文 > 详细

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

时间:2019-08-21 20:06:37      阅读:79      评论:0      收藏:0      [点我收藏+]

标签:log   each   let   location   cap   pre   sea   sub   arch   

主要代码

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 模拟登录验证并跳转当前页面

标签:log   each   let   location   cap   pre   sea   sub   arch   

原文地址:https://blog.51cto.com/13496570/2431500

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!