美文网首页
在数组中调用方法需要使用async await

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

作者: O人心 | 来源:发表于2021-07-09 13:38 被阅读0次
原因:在数组循环中调用方法,第一次循环,调用方法,方法没走完,就会再次循环,所以需要使用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) => {});
    },

相关文章

网友评论

      本文标题:在数组中调用方法需要使用async await

      本文链接:https://www.haomeiwen.com/subject/tukfpltx.html