map中使用await 异步函数

let result=await Promise.all(dataComments.map(async (ele)=>{
                 return (async ()=>{
                       let resData= await articleApi.getOneArticle(ele.article_id);
                       let titleData=resData.data;
                       ele.title=titleData.title
                       console.log("111")
                       return ele;
                 })()
          }))

如上所示即可实现map中异步函数的操作。

猜你喜欢

转载自www.cnblogs.com/LULULI/p/10831523.html