使用Promise发送多个异步请求, 全部完成后再执行

const datas = idList
  .map(id => url+'/id')
  .map(url => fetch(url).then(res => res.json()));
const p = new Promise.all(datas)
  .then(data => {...})


const datas = idList
  .map(id => url+'/id')
  .map(url => fetch(url).then(res => res.json()));
const foo = await Promise.all(datas);
const series = foo.map(data => {...})

 

posted @ 2019-04-26 16:54  冰糖雪梨橙  阅读(1110)  评论(0编辑  收藏  举报