当前位置:   article > 正文

Axios设置请求超时时间 timeout_axios timeout

axios timeout
1.axios全局设置网络超时
axios.defaults.timeout = 30 * 1000; // 30s
2. 单独对某个请求设置网络超时
  1. axios.post(url, params, {timeout: 1000})
  2. .then(res => {
  3. console.log(res);
  4. })
  5. .catch(err=> {
  6. console.log(err);
  7. })
  8. })
3.webpack的dev的proxyTable的超时时间设置
  1. dev: {
  2. // Paths
  3. assetsSubDirectory: 'static', // 静态资源文件夹
  4. assetsPublicPath: '/', // 发布路径
  5. // 代理配置表,在这里可以配置特定的请求代理到对应的API接口
  6. // 使用方法:https://vuejs-templates.github.io/webpack/proxy.html
  7. proxyTable: {
  8. '/api': {
  9. timeout: 20000, // 请求超时时间
  10. target: 'http://localhost:8080', // 目标接口域名
  11. changeOrigin: true, // 是否跨域
  12. pathRewrite: {
  13. '^/api': '' // 重写接口
  14. }
  15. },
  16. // Various Dev Server settings
  17. host: 'localhost', // can be overwritten by process.env.HOST
  18. port: 8866, // can be overwritten by process.env.PORT, if port is in use, a free one will be determined
  19. },

声明:本文内容由网友自发贡献,转载请注明出处:【wpsshop】
推荐阅读
相关标签
  

闽ICP备14008679号