RN Fetch处理时间超时

2017-08-18  本文已影响187人  亦晴工作室

1、打开目录 /xxxx/node_modules/whatwg-fetch/fetch.js

2、
我们加上一段给xhr对象的timeout属性赋值的代码:
//我们只需要加上下面这段代码即可
if(init!=null&&init.timeout!=null){
      xhr.timeout=init.timeout;
}

然后在我们调用的时候,我们就可以开心的传递我们的timeout参数了:

let response = await fetch(url, {
              headers: this.method == 'GET' ? null : this.headers,
              method: this.method,
              body: this.method == 'GET' ? null : this.body,
              timeout:10000
});
上一篇 下一篇

猜你喜欢

热点阅读