requestTask.onChunkReceived(function (response) {
const arrayBuffer: any = response.data;
let responseText = '';
const uint8Array: any = new Uint8Array(arrayBuffer);
let text = String.fromCharCode.apply(null, uint8Array);
responseText += text;
const lastIndex = responseText.lastIndexOf('\n', responseText.length - 2)
let chunk = responseText
let chunkArr = []
if (lastIndex !== -1) {
let linesArray: any = responseText.split('\n');
chunkArr = linesArray.filter((item: any) => item !== '');
} else {
chunkArr.push(chunk)
}
try {
let stopStatus = _this.data.stopStatus
if (stopStatus) {
_this.setrestart()
requestTask.abort(); // 终止请求
}else{
let replysources: any = _this.data.replysources
let index = replysources.length - 1;
replysources[index].text = replysources[index].text + text
//markdown '#1E1E1E'
replysources[index].textmarkdown = app.towxml(replysources[index].text, 'markdown', {
theme:'dark'
})
_this.setData({
replysources: replysources,
process_status: true, //表示进程正在继续
})
}
}
catch (error) {
//
console.log("error1:", error)
}
})
上述是接收返回数据,并通过setdata进行输出,但是返回的内容过长,点击停止输出时,不能响应。返回的内容少,点击停止时能快速响应的,请问下老铁们有好的解决方法吗?
参考 https://developers.weixin.qq.com/miniprogram/dev/framework/performance/tips/runtime_setData.html 3.4 setData 应只传发生变化的数据
对setData进行优化,对Array|Object只修改变化或者新增的部分
有没有老哥解答下