Vue-resource拦截器判断token失效跳转的实例

软件发布|下载排行|最新软件

当前位置:首页IT学院IT技术

Vue-resource拦截器判断token失效跳转的实例

  2020-05-16 我要评论

在拦截器中设置全局的token判断,意味着每次http请求都会校验token,与后台约定好的token过期返回码可以自定义跳转路径;

var token = window.localStorage.getItem("token");
Vue.http.interceptors.push(function(request, next) {
  request.headers.set('token', token); //setting request.headers
  next(function(response){
    if(response.body.code===401){ //与后台约定登录失效的返回码
      parent.location.href ='/login.html';
    }
    return response
  })
})

以上这篇Vue-resource拦截器判断token失效跳转的实例就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持。

Copyright 2022 版权所有 软件发布 访问手机版

声明:所有软件和文章来自软件开发商或者作者 如有异议 请与本站联系 联系我们