vue路由守卫并向后台发送token
vue代码
//全局路由首位;当路由发生异常首先执行的方法
router.beforeEach((to, from, next) => {
//是否被认证
var isAuthenticated = false;
//1.从localStorage获取用户的token 是否为空
this.token = localStorage.getItem('token') //从localStorage获取用户的token
//2.判断token是否为null ,为Null代表这个是用户未登录
if (this.token != null) {
var isAuthenticated = true;
//需要在后台验证这个token是或正确
axios.defaults.headers = {
"token": this.token
}
}
if (to.name !== 'login' && !isAuthenticated) next({ name: 'login' })
else next()
})
vue路由守卫并向后台发送token的更多相关文章
- react router @4 和 vue路由 详解(八)vue路由守卫
完整版:https://www.cnblogs.com/yangyangxxb/p/10066650.html 13.vue路由守卫 a.beforeEach 全局守卫 (每个路由调用前都会触发,根据 ...
- vue路由守卫用于登录验证权限拦截
vue路由守卫用于登录验证权限拦截 vue路由守卫 - 全局(router.beforeEach((to, from, next) =>来判断登录和路由跳转状态) 主要方法: to:进入到哪个路 ...
- Vue | 路由守卫面试常考
前言 最近在整理基础,欢迎掘友们一起交流学习 结尾有彩蛋哦! Vue Router 路由守卫 导图目录 路由守卫分类 全局路由守卫 单个路由守卫 组件路由守卫 路由守卫执行的完整过程 路由守卫分类 全 ...
- vue路由守卫应用,监听是否登录
路由跳转前做一些验证,比如登录验证,是网站中的普遍需求. 对此,vue-route 提供的 beforeRouteUpdate 可以方便地实现导航守卫(navigation-guards). 导航守卫 ...
- Vue路由守卫(跳转页面置顶的处理方)
在用Vue 框架开发时,在电脑调试没有任何问题,但是用手机调试时会发现页面跳转的不对.就是跳转时页面展示的滑动位置不对,会保留上次跳转页面时的跳转位置.因此需要对页面的路由跳转进行优化,需要用到Vue ...
- vue路由守卫
路由守卫 //路由进来之时 beforeRouteEnter(to, from, next) { console.log(this, 'beforeRouteEnter'); // undefined ...
- vue路由守卫触发顺序
不同组件之间的路由跳转流程图 导航被触发(A–>B) 调用A组件内路由守卫beforeRouteLeave(to,from,next) 调用全局路由前置守卫router.beforeEach(t ...
- vue路由守卫+cookie实现页面跳转时验证用户是否登录----(二)设置路由守卫
上一篇我们已经封装好了cookie方法,登录成功之后也可以吧用户信息存到cookie中,接下来需要在router/index.js中引入一下cookie.js文件 然后继续添加以下代码 /* * be ...
- Vue路由守卫之路由独享守卫
路由独立守卫,顾名思义就是这个路由自己的守卫任务,就如同咱们LOL,我们守卫的就是独立一条路,保证我们这条路不要被敌人攻克(当然我们也得打团配合) 在官方定义是这样说的:你可以在路由配置上直接定义 ...
- Vue路由守卫之组件内路由守卫
beforeRouteEnter,进入路由前.需要注意这里不能使用this,因为我们使用的是进入路由之前,那会组件还没创建,得不到this这个属性,所有我们只能使用过vm异步语句来让 ...
随机推荐
- JS正则表达式大全(整理详细且实用)2
javascript的17种正则表达式 "^\\d+$" //非负整数(正整数 + 0) "^[0-9]*[1-9][0-9]*$" //正整数 "^ ...
- 解决MyBatis-Plus修改为null值无效的问题
@TableField(strategy = FieldStrategy.IGNORED)
- Something Just Like This
I've been reading books of old我遍读旧籍 The legends and the myths那些古老传奇和无边神秘 Achilles and his gold如阿喀琉斯和 ...
- mac新仙剑奇侠传 2018
新仙剑奇侠传 201803重制 下载,挂载后,拖动app到applications应用程序 文件夹即可. https://590m.com/f/28636472-500476381-5c8846 (访 ...
- javaScript面向对象(继承篇)
一.构造函数继承 function Parent() { this.money = '2亿' this.eat = function () { console.log('吃饭') } } func ...
- (linux笔记)开放防火墙端口
关闭防火墙 CentOS 7.RedHat 7 之前的 Linux 发行版防火墙开启和关闭( iptables ): 即时生效,重启失效 #开启 service iptables start #关闭 ...
- 解决 使用 params 传递参数 必须 加上 name
{path:'/blog',name:'blog',params:{is:true}}
- zk api连接超时问题 org.apache.zookeeper.KeeperException$ConnectionLossException: KeeperErrorCode = ConnectionLoss for
遇到 org.apache.zookeeper.KeeperException$ConnectionLossException: KeeperErrorCode = ConnectionLoss fo ...
- python3.7 sorted 自定义排序
from functools import cmp_to_keyls=['9','23','3','56','78']sorted(ls, key=cmp_to_key(lambda x, y: in ...
- Java-AES256加密Util
1 public class AES256Util { 2 3 /** 4 * 密钥, 256位32个字节 5 */ 6 public static final String DEFAULT_SECR ...