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