uniapp开发时编译成微信小程序时并在小程序开发工具运行时,时而会出现:
TypeError: Invalid attempt to destructure non-iterable instance.
In order to be iterable, non-array objects must have a [Symbol.iterator]() method.
这样到报错,无法定位问题。
因为什么才会导致这样的问题。
booboom
- 发布:2020-09-25 15:23
- 更新:2021-01-11 10:37
- 阅读:6827
j***@qq.com - 码梦天涯
应该是在当做数组解构吧?比如说const [err, res] = await uni.request(xxx),之前我也遇到过,然后手动改成了这样
const [reqErr, reqResponse] = await new Promise<[UniReqError, UniReqResult]>(resolve => {
uni.request({
...requestOptions,
success: result => resolve([void 0, result as unknown as UniReqResult]),
fail: result => resolve([result, void 0 as unknown as UniReqResult]),
});
});