微信小程序在wx.request时enableChunked设置为true,然后设置requestTask.onChunkReceived的回调;在该回调执行时,一律报错:“global is not defined",该回调方法内代码无法执行。参考代码如下,未使用到global变量。从提示中看属于框架内部错误,pc微信版本见图中,开发工具和手机上都运行正常,且更换任何基础库版本依然报错。
:
const requestTask = wx.request({
url: "https:xxxxxxxx/api",
method: "POST",
enableChunked: true,
header: {
"accept-language": "zh-CN",
'content-type': 'application/json' // 默认值
},
data: {
"stream": true
},
success(res) {
},
fail(res) {
}
});
requestTask.onChunkReceived((res: any) => {
});
试试更新内核https://docs.qq.com/doc/DRmROZXpBVmNxYURY
请具体描述问题出现的流程,并提供能复现问题的简单代码片段(https://developers.weixin.qq.com/miniprogram/dev/devtools/minicode.html)。
我改成PC端(实测Mac也一样)就 responseType :'text/html', enableChunked:true
手机端正常使用
PC端在不支持流式响应,需要兼容处理https://developers.weixin.qq.com/community/develop/doc/000c26be3c0d08c47e7f7b32756c00