美文网首页
React_Native的Fetch时间超时timeout设置

React_Native的Fetch时间超时timeout设置

作者: 亦晴工作室 | 来源:发表于2017-08-01 11:53 被阅读93次

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});

相关文章

网友评论

      本文标题:React_Native的Fetch时间超时timeout设置

      本文链接:https://www.haomeiwen.com/subject/cgkjlxtx.html