在数组中调用方法需要使用async await

2021-07-09  本文已影响0人  O人心
原因:在数组循环中调用方法,第一次循环,调用方法,方法没走完,就会再次循环,所以需要使用async await
this.infoForm.acadList.map(async (r) => {
          let recordId =
            this.infoForm.picUploadTime +
            this.hoursInfoId +
            this.infoForm.idNumber;
          await this.getFiles(
            this.$constant.FILE_TYPE.INFO_ACADEMIC_TITLE,
            recordId + r.no,
            "Acad",
            r.no
          );
        });
async getFiles(typeId, recordId, type, no) {
      await PersonalCenterApi.getClass()
        .getFiles(typeId, recordId)
        .then((res) => {
             this.infoForm.acadList.forEach((r, index) => {
                  if (r.no == no) {
                    this.$set(
                      this.infoForm.acadList[index],
                      "imgAcad",
                      res.data.data
                    );
                  }
                });
              }
        })
        .catch((err) => {});
    },
上一篇 下一篇

猜你喜欢

热点阅读