請求超時的處理——axios.defaults.timeout


axios.defaults.timeout的作用其實就是,請求時間超出設置時間后,如果沒有請求成功就執行錯誤函數。

//全局設置超時時間
axios.defaults.timeout = 30000;

//單獨對請求設置網絡超時

let timeout = parseInt(paramsTimeout);
this.$http.post(url, params, {timeout: timeout})
  .then(res => {
    console.log('response='+response);
  })
  .catch(reason => {
    console.log('reason'+reason);
  })
})
//如果到達30000毫秒未請求到接口的數據就會執行catch中的語句



參考https://www.cnblogs.com/ckmouse/p/12777709.html,https://blog.csdn.net/m0_48494425/article/details/119912421


免責聲明!

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



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