axios设置超时时间不生效是什么原因?-灵析社区

半寸时光爱思考

设置超时时间是50毫秒,接口还能正常请求,超时时间不生效 ![image.png](https://wmprod.oss-cn-shanghai.aliyuncs.com/c/user/20241015/4b46228739c50f79b3e64b11f774af8c.png) axios({ method: 'get', url: '', params: {}, timeout: 50 }).then(res => { console.log('res---', res) }).catch(error => { if (error.config.timeout == 50) { Message.error('请求超时,请检查网络') } else { console.log(error) } }) 全局设置axios.defaults.timeout = 50 也不生效

阅读量:93

点赞量:0

问AI
小青梅
你可以尝试一下把timeout这样写 const service = axios.create({ ......,相关配置 // 超时时间 单位是ms,这里设置了3s的超时时间 timeout: 3 * 1000 })