array.push(api.post())
array.push(api.post())
Promise.all(array).then(arr=>{
arr.forEach(res=>{
})
})
本文介绍了一种利用JavaScript中的Promise.all方法来并发处理多个API请求的方法。通过将多个api.post()请求放入数组中,并使用array.push()方法添加,最后通过Promise.all(array)确保所有请求完成后才继续执行后续逻辑。
array.push(api.post())
array.push(api.post())
Promise.all(array).then(arr=>{
arr.forEach(res=>{
})
})