在項(xiàng)目中,所有請(qǐng)求都是走統(tǒng)一封裝過的axios,統(tǒng)一設(shè)置了超時(shí)時(shí)間:
const service = axios.create({
baseURL: process.env.VUE_APP_BASE_API, // url = base url + request url
timeout: 1 * 60 * 1000 // request timeout (ms)
})
但是有一個(gè)接口耗費(fèi)時(shí)間巨長,網(wǎng)絡(luò)不好時(shí)經(jīng)常會(huì)超時(shí),改統(tǒng)一設(shè)置的超時(shí)時(shí)間感覺不太好,所以想針對(duì)這個(gè)請(qǐng)求單獨(dú)設(shè)置超時(shí)時(shí)間。
以下是普通請(qǐng)求:文章來源:http://www.zghlxwxcb.cn/news/detail-588577.html
// 修改文件名稱
export function aaa(data) {
return request({ //request里封裝了axios
url: `/aaa/bbb/ccc`,
method: 'post',
data
})
}
單獨(dú)設(shè)置請(qǐng)求超時(shí)時(shí)間:文章來源地址http://www.zghlxwxcb.cn/news/detail-588577.html
export function bbb(data, applyNo) {
return request({
url: `/aaa/bbb/ddd`,
method: 'post',
headers: { // 可直接在請(qǐng)求頭上添加屬性
'ApplyNo': applyNo
},
timeout: 3 * 60 * 1000,
data
})
}
到了這里,關(guān)于axios 設(shè)置超時(shí)時(shí)間 timeout的文章就介紹完了。如果您還想了解更多內(nèi)容,請(qǐng)?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!