在场景:一个表格数据需要上传,每行表格需要上传图片->这就需要在提交时对数据也就是数组进行处理(先将每个元素图片上传拿到图片id
这种情况我刚开始就用的map处理,然后问题来了,提交的接口调用了,但是上传图片的接口没调用,用了async await也没用
let shopContactList = editForm.value.shopContacts.map(async (item: any) => {
let middle: any
if (item.fileList.length && !item.wechatCodeImageID) {
middle = await uploadImage(item.fileList[0])
}
return {
name: item.name,
phone: item.phone,
wechatCodeImageID: middle,
}
})
->然后我就用了forEach去处理
let shopContactList: any = []
editForm.value.shopContacts.forEach(async (item: any) => {
let middle: any
if (item.fileList.length && !item.wechatCodeImageID) {
middle = await uploadImage(item.fileList[0])
}
shopContactList.push({
name: item.name,
phone: item.phone,