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/

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM