首页 > 其他分享 >无感刷新token

无感刷新token

时间:2023-06-27 20:12:22浏览次数:34  
标签:data 无感 method token api 刷新 config response

无感刷新 token

//首先需要在响应拦截里面 加一个 code反馈码的判断  是401就调用刷新token的方法

//响应拦截
api.interceptors.response.use(
  (response: any) => {
    if (response.data.code == 200) {
      done();
      return response;
    } else if (response.data.code == 401) {
      return tokenss(response);   //这个我单独封装了tokenss方法 需要传递response返回值回来
    }
  },
//返回值与后端规定  最新token  和刚刚 发送请求的信息 是哪个请求地方 和携带的东西

//例如response 返回的是: 就是401返回的数据
//method: 'post', url: '/tokenOut', data: { token: '11111' }

//封装的tokenss 处理:

import api from "@/api"; //引入创建的路由实例
export default (response: any) => { //response是返回的数据
  sessionStorage.setItem("token", response.data.conf.data.token);
    //把跟着401一起返回的最新token马上存本地
    //再调用上一个接口 上一个接口信息应该跟着一起返回
  let config = response.data.conf;
    //后端返回上一个发送的请求数据
  if (config.method == "post") {  //判断是什么请求
    return api({method: config.method, url: config.url, data: config.data});
  } else {
    //其他请求   因为传值有一些不一样 所以要区分
    return api({url: config.url, method: config.method, params: config.data});
  }
};

api({})这个也是调取接口  具体配置可以百度 axios JSON请求配置
和
xxx.get("xxx",params:{xxx})  一样

标签:data,无感,method,token,api,刷新,config,response
From: https://www.cnblogs.com/yitiaogua/p/17509817.html

相关文章

  • TypeError: token.type.endsWith is not a function
    起因公司产品项目拉下来,安装完依赖就报这个错误token.type.endsWithisnotafunction 解决方案发现是eslint的版本将 babel-eslint版本为10.1.0,把版本降为8.2.2,即重新安装指定版本的依赖。重新安装,并重启后,解决问题 [email protected] ......
  • 【Node】node 报错:tagOffsetsMap[tag] ??= [];...SyntaxError: Unexpected token ,‘??=
    安装的node版本不支持空值赋值运算符(??=)更换合适的node版本就行更多支持请在node.green上查看各种语法支持的版本参考文章NodeJS中的空合并赋值运算符(??=)......
  • 【HMS Core】web端网页应用集成账号服务,请求/oauth2/v3/token返回状态码403
    【问题描述】web端网页应用接入华为账号,请求/oauth2/v3/token返回状态码403请求代码:响应日志:【问题分析】这是由于跨域访问报错了,建议从服务器端调用token接口重试,不要把client_secret暴露到web端【解决方案】服务器端调用token接口参考链接:https://developer.huawei.com/consumer......
  • 刷新20项代码任务SOTA,Salesforce提出新型基础LLM系列编码器-解码器Code T5+
    前言 大型语言模型(LLMs)最近在代码层面的一系列下游任务中表现十分出彩。通过对大量基于代码的数据(如GitHub公共数据)进行预训练,LLM可以学习丰富的上下文表征,这些表征可以迁移到各种与代码相关的下游任务。但是,许多现有的模型只能在一部分任务中表现良好,这可能是架构和......
  • RHEL CentOS Debian Ubuntu 如何刷新 DNS 缓存
    RHELCentOSDebianUbuntu如何刷新DNS缓存全文:如何刷新DNS缓存(macOS,Linux,Windows)UnixLinuxWindows如何刷新DNS缓存(macOS,FreeBSD,RHEL,CentOS,Debian,Ubuntu,Windows)请访问原文链接:https://sysin.org/blog/how-to-flush-dns-cache/,查看最新版。原创......
  • 如何刷新 DNS 缓存 (macOS, Linux, Windows)
    如何刷新DNS缓存(macOS,Linux,Windows)UnixLinuxWindows如何刷新DNS缓存(macOS,FreeBSD,RHEL,CentOS,Debian,Ubuntu,Windows)请访问原文链接:https://sysin.org/blog/how-to-flush-dns-cache/,查看最新版。原创作品,转载请保留出处。作者主页:sysin.org刷新或者......
  • Linux 如何刷新 DNS 缓存
    Linux如何刷新DNS缓存全文:如何刷新DNS缓存(macOS,Linux,Windows)UnixLinuxWindows如何刷新DNS缓存(macOS,FreeBSD,RHEL,CentOS,Debian,Ubuntu,Windows)请访问原文链接:https://sysin.org/blog/how-to-flush-dns-cache/,查看最新版。原创作品,转载请保留出处。......
  • Authentication token manipulation error
    无法修改密码:Authenticationtokenmanipulationerrorroot@VM:/etc/pam.d#passwdubuntupasswd:Authenticationtokenmanipulationerrorpasswd:passwordunchanged 解决方案:将以下行注释#passwordrequisitepam_pwquality.somin......
  • 1.element表头居中内容左对齐, 2.自定义el-table中新增编辑表格不刷新的问题。
    一、<el-table :header-cell-style="{'text-align':'left'}">...<el-table-column:cell-style="{'text-align':'left'}">...</el-table-column></el-table> 二、this.$se......
  • vue项目本地启动history路由模式刷新页面404
    背景:之前一直用hash模式,改成history模式后刷新页面404解决:vue.config.js中publicPath:"/"如果是线上服务则还需要后端修改一些配置,见链接点击查看......