forEach中调接口,等接口全部调完,再去赋值

async queryTable() {
      this.loading = true;
      const result = await crmApplySceneIndexAPI(this.searchForm);
      this.total = result.data.totalRow;

      const list = result.data.list || [];
      if (list && list.length > 0) {
        const promiseArray = [];
        list.forEach(item => {
          const promise = new Promise((resolve, reject) => {
            adminFilePreview(item.fileEntity.fileId).then(res1 => {
              if (res1) {
                this.$set(item, "imgUrl", URL.createObjectURL(res1.data));
                resolve();
              }
            });
          });
          promiseArray.push(promise);
        });
        Promise.all(promiseArray).then(() => {
          this.loading = false;
          this.tableData = list;
        });
      }
    },

 

posted @ 2024-01-31 12:44  鼓舞飞扬  阅读(86)  评论(0编辑  收藏  举报