【接口请求配置】axios 某个单独接口的个性化配置

数字化管理平台
Vue3+Vite+VueRouter+Pinia+Axios+ElementPlus教程
权限系统-商城
个人博客地址

干过前端开发的小伙伴都知道,项目中所有的接口请求都是走统一封装过的 axios,即:全局请求配置。

const request = axios.create({
  baseURL: process.env.VUE_APP_BASE_API, 
  timeout: 50000 
})

现在有这么一个需求:有一个接口耗费时间巨长,网络不好时经常会超时。去改统一设置的超时时间又不太现实,所以想针对这个请求单独设置超时时间。

// 平台数据导出
export function statListExport (data) {
  return request({
    url: `/product/carrier/statList/export`,
    method: 'post',
    data,
    responseType: 'arraybuffer',
    timeout: 10000
  })
}

注:这里除了可以单独配置请求超时时间, 其它属性配置也可直接在请求头上添加。

猜你喜欢

转载自blog.csdn.net/qq_39335404/article/details/129478460