From b53bdc5885d9d63d595ee4cb1f9a60a45a9b8b99 Mon Sep 17 00:00:00 2001 From: luckyadam Date: Mon, 23 Apr 2018 01:22:55 +0800 Subject: [PATCH] =?UTF-8?q?fix(taro):=20Taro.request=20=E6=96=B9=E6=B3=95H?= =?UTF-8?q?5=E7=AB=AF=E8=BF=94=E5=9B=9E=E9=94=99=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/taro/src/native-api.js | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/packages/taro/src/native-api.js b/packages/taro/src/native-api.js index 37d557163bbc..bb79496bfcf7 100644 --- a/packages/taro/src/native-api.js +++ b/packages/taro/src/native-api.js @@ -59,19 +59,23 @@ function request (options) { params.mode = options.mode params.credentials = options.credentials params.cache = options.cache + const res = {} return fetch(url, params) .then(response => { - const res = { - statusCode: response.status, - header: response.headers - } + res.statusCode = response.status + res.header = response.headers if (options.responseType === 'arraybuffer') { - res.data = response.arrayBuffer() - } else if (options.dataType === 'json' || typeof options.dataType === 'undefined') { - res.data = response.json() - } else if (options.responseType === 'text') { - res.data = response.text() + return response.arrayBuffer() + } + if (options.dataType === 'json' || typeof options.dataType === 'undefined') { + return response.json() + } + if (options.responseType === 'text') { + return response.text() } + return Promise.resolve(null) + }).then(data => { + res.data = data return res }) }