React_Native的Fetch时间超时timeout设置

1、打开目录 /xxxx/node_modules/whatwg-fetch/fetch.js
2、修改设置


React_Native的Fetch时间超时timeout设置_第1张图片

我们加上一段给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设置)