axios.post('/operationlog/list', moduleParams).then((res) => {
if (res.status === 200) {
this.moduleList = res.data.items;
stepParams.append('category', "");
stepParams.append('needPlayback', true);
for (let i = 0; i < this.moduleList.length; i++) {
stepParams.set('category', this.moduleList[i].category)
axios.post('/operationlogitem/list', stepParams).then((res) => {
console.log(res.data.items);
}).catch((e) => {
console.log(e);
})
}
}
}
代码如上,根据外层请求获取到多个不同的category,但是for循环是同步,里面的post请求是异步的,所以始终以最后一项的category为参数发送请求.请问如何修改代码按照每一项的category参数发送post请求,目前只知道用递归解决,有没有其他办法?
可以用生成器函数或者async/await再用babel转