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);
  }
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章