zoukankan      html  css  js  c++  java
  • axios设置请求超时时间 timeout

    1. axios全局设置网络超时

    axios.defaults.timeout = 30 * 1000; // 30s

    2. 单独对某个请求设置网络超时

    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: 30000, // 请求超时时间
                target: 'http://127.0.0.1:3006', // 目标接口域名
                changeOrigin: true, // 是否跨域
                pathRewrite: {
                '^/api': '' // 重写接口
            }
        },
        // Various Dev Server settings
        host: 'localhost', // can be overwritten by process.env.HOST
        port: 4200, // can be overwritten by process.env.PORT, if port is in use, a free one will be determined
    }    

    原文链接:https://blog.csdn.net/l508742729/article/details/105148480/

     

  • 相关阅读:
    easyui好例子,值得借鉴
    DDL 和DML 区别
    兼容IE的文字提示
    搭代理
    美国服务器
    跟随滚动条滚动
    JS Array对象
    JS 内置对象 String对象
    JS 对象
    JS 二维数组
  • 原文地址:https://www.cnblogs.com/momo798/p/15620362.html
Copyright © 2011-2022 走看看