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; }); } },