Skip to content

Commit

Permalink
fix(taro): Taro.request 方法H5端返回错误
Browse files Browse the repository at this point in the history
  • Loading branch information
luckyadam committed Apr 22, 2018
1 parent 7cba914 commit b53bdc5
Showing 1 changed file with 13 additions and 9 deletions.
22 changes: 13 additions & 9 deletions packages/taro/src/native-api.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
})
}
Expand Down

0 comments on commit b53bdc5

Please sign in to comment.