1.封装一个fetch方法
function fetch(params: params) {
const task = uni.request({
url: params.url,
method: params.method,
enableChunked: true, //注意配置
data: params,
header: params.header,
success: (res) => {},
fail: (err) => {},
complete: () => {}
})
return task
}
2.使用TextDecoder转换
编码
requestTask.onChunkReceived(function(res) {
let decoder = new TextDecoder('utf-8')
let text = decoder.decode(new Uint8Array(res.data))
console.log(text)
})