① for循环中同步顺序执行接口请求
for await…of 实现(推荐):这是 ES6 中的新语法,可以在循环中使用 await
来处理异步操作。示例代码如下:
// 根据批次调用健康管理接口
async handleHealthApi() {
// 使用 for await...of 实现处理异步操作
for await (let item of this.batchList) {
let params = `?$filter=BatchID eq '${item.BatchId}'&$orderby=ImmunityDate`;
let { value } = await immtipApi.ImmunityPromptBatch(params);
// do something...
}
}