首页 > 解决方案 > 什么是axios默认超时

问题描述

我在文档步骤中找到了设置超时值。

const instance = axios.create({
  baseURL: 'https://some-domain.com/api/',
  timeout: 1000,
  headers: {'X-Custom-Header': 'foobar'}
});

但是我在 axios 官方文档中找不到默认值 - https://github.com/axios/axios

默认超时是多少?

此外,AXIOS 下方使用 http 服务器/客户端(https://nodejs.org/api/http.html#http_class_http_clientrequest

它是否使用http默认超时?我看到我的程序在 2 分钟后超时。

标签: axios

解决方案


根据自述文件,它是 0 表示没有超时

//timeout指定请求超时前的毫秒数。

// 如果请求时间超过timeout,请求将被中止。超时:1000,

// 默认是0(没有超时)

https://github.com/axios/axios/blob/master/README.md#request-config


推荐阅读