使用 fetch 的时候遇到了一个比较奇怪的问题,
我的代码是这样的:
1 2 3 4 5 6 7
| fetch(api) .then(this.json) .then(this.unWrap) .catch((error) => { console.warn("get-error: " + error + ", api=" + api); return {success: false, msg: error} });
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
| static json = (response) => { console.log("response", response); let json = response.json(); console.log("json", json); setTimeout(() => null, 0); return json; }; static unWrap = (responseJson) => { console.log("responseJson", responseJson); if (responseJson.status !== 0 && responseJson.status !== 200) { throw responseJson.msg; } return {success: true, data: responseJson.data}; };
|
更多信息可到:issues-6679