map中使用async await

##map中使用async await

map函数里面的方法是同步的,异步请求用async await
async 返回的是Promise

getList() {
      this.loading = true;
      listInquiry(this.queryParams).then(response => {
      //添加Promise.all是因为return返回的是数组形式的Promise
        Promise.all( 
          response.rows.map(async item => {
            await getDemand(item.typeId).then(res => {
              if (res.code == 200) {
                item.demandName = res.data.title;
              }
            });
            return item;
          })
        ).then(res => {
          this.inquiryList.push(...res);
          this.loading = false;
          this.total = response.total;
        });
      });

你可能感兴趣的:(学习笔记)