JS forEach发送请求实现同步
Promise.all(
this.idList.map( ({id}) =>{
return new Promise(async (resolve, reject) =>{
await this.getA(id).then(() => {
this.getB(id).then(() => {
this.getC(id).then(()=>{
resolve();
})
});
});
})
})
).then(() =>{
})
参考 js forEach循环调用异步方法,如何实现同步
for循环请求同步
methods: {
......
getList(ids) {
return new Promise((resolve, reject) => {
listByIds(ids).then(response => {
resolve(response);
})
})
},
getIds(){
return new Promise((resolve, reject) => {
Ids().then(response =>{
resolve(response);
})
})
}
async getDatas(){
this.ids = await this.getIds();
this.dataList = await this.getList(this.ids);
}
.....
}