尚未崩坏 发表于 2024-6-26 03:59:51

Axios设置哀求超时时间 timeout

1.axios全局设置网络超时

axios.defaults.timeout = 30 * 1000; // 30s 2. 单独对某个哀求设置网络超时

axios.post(url, params, {timeout: 1000})
.then(res => {
    console.log(res);
})
.catch(err=> {
    console.log(err);
})
}) 3.webpack的dev的proxyTable的超时时间设置

dev: {
    // Paths
    assetsSubDirectory: 'static', // 静态资源文件夹
    assetsPublicPath: '/', // 发布路径
    // 代理配置表,在这里可以配置特定的请求代理到对应的API接口
    // 使用方法:https://vuejs-templates.github.io/webpack/proxy.html
    proxyTable: {
      '/api': {
      timeout: 20000, // 请求超时时间
      target: 'http://localhost:8080', // 目标接口域名
      changeOrigin: true, // 是否跨域
      pathRewrite: {
          '^/api': '' // 重写接口
      }
      },
    // Various Dev Server settings
    host: 'localhost', // can be overwritten by process.env.HOST
    port: 8866, // can be overwritten by process.env.PORT, if port is in use, a free one will be determined
},

免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!更多信息从访问主页:qidao123.com:ToB企服之家,中国第一个企服评测及商务社交产业平台。
页: [1]
查看完整版本: Axios设置哀求超时时间 timeout