美文网首页
vue项目中axios请求统一配置了超时时间,单独接口请求时重设

vue项目中axios请求统一配置了超时时间,单独接口请求时重设

作者: 爱学习的小仙女早睡早起 | 来源:发表于2022-04-12 13:41 被阅读0次

场景:通过axios.create 对axios做拦截器处置,统一设置了超时时间,文件上传或者文件合成需要单独处理

import axios from "axios";
var AuthToken = sessionStorage.getItem("slAuthToken");

const service = axios.create({
    baseURL: "/",
    withCredentials: true, // 开启withCredentials后,服务器才能拿到你的cookie,当然后端服务器也要设置允许你获取你开启了才有用
    timeout: 6000,
});

根据官网推荐:axios配置官网

image.png

具体实现:
默认请求时间接口请求:


// 任务新建
export function newTaskAdd(data) {
  return request({
    url: '/api/taskPlan/addapi',
    method: 'post',
    data
  })
}


重设超时时间的接口请求:

// 文件上传
export function newTaskAdd(data) {
  return request({
    url: '/api/file/upload',
    method: 'post',
    timeout: 60 * 60 * 1000,
    data
  })
}


相关文章

网友评论

      本文标题:vue项目中axios请求统一配置了超时时间,单独接口请求时重设

      本文链接:https://www.haomeiwen.com/subject/ljggsrtx.html