zoukankan      html  css  js  c++  java
  • vue-router的beforeEach的使用?

    解决思路就是首先将每次登录之前首先将后台传给的token记录下来判断是否存在(或者判断用户名信息是否存在),接下来才判断是跳转登录页面还是首页
    router.beforeEach((to, from, next) => {
    var userInfo = window.localStorage.getItem('token');//获取浏览器缓存的用户信息
    if(userInfo){ //如果有就直接到首页咯
    next();
    } else {
    if(to.path=='/login'){ //如果是登录页面路径,就直接next()
    next();
    } else { //不然就跳转到登录;
    next('/login');
    }
     
    }
    })
  • 相关阅读:
    tarjan algorithm
    最小生成树
    Manacher's Algorithm (马拉车算法)
    KMP
    Trie(字典树)
    Hash
    GDB调试
    图论
    扫描线
    STL
  • 原文地址:https://www.cnblogs.com/duanzhange/p/10303614.html
Copyright © 2011-2022 走看看