1吧雹、打開目錄 /xxxx/node_modules/whatwg-fetch/fetch.js
我們加上一段給xhr對象的timeout屬性賦值的代碼:
//我們只需要加上下面這段代碼即可
if(init!=null&&init.timeout!=null){
xhr.timeout=init.timeout;
}
然后在我們調用的時候魏身,我們就可以開心的傳遞我們的timeout參數(shù)了:
let response = await fetch(url, {
headers: this.method == 'GET' ? null : this.headers,
method: this.method,
body: this.method == 'GET' ? null : this.body,
timeout:10000
});