Vue 使用Axios实现同步请求
JS forEach发送请求实现同步Promise.all(this.idList.map( ({id}) =>{return new Promise(async (resolve, reject) =>{await this.getA(id).then(() => {this.getB(id).then(() => {this.ge
·
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(() =>{
//forEach循环请求结束后执行的方法
})
for循环请求同步
methods: {
......
getList(ids) {
return new Promise((resolve, reject) => {
//listByIds api.js中声明的接口
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);
}
.....
}
更多推荐
所有评论(0)