【vue】for循环里嵌套了异步请求如何使它执行完了再执行下面代码
async updateGood(state) {for (let i = 0; i < this.file.length; i++) {//MVP: awaitawait this.uploadImg(this.file[i]);}console.log(this.oldPhoto.concat(this.imgName));const res = await updateBasicsPr
·
async uploadImg(file) {
let formData= new FormData();
formData.append("photo", file);
const { data: data } = await uploadProductPicture(formData);
console.log(data);
this.imgName.push(data);
},
async updateGood(state) {
for (let i = 0; i < this.file.length; i++) {
//MVP: await
await this.uploadImg(this.file[i]);
}
console.log(this.oldPhoto.concat(this.imgName));
const res = await updateBasicsProduct({
id: this.goodId,
name: this.newName,
schoolId: this.newSchool,
areaId: this.newArea,
photos: this.oldPhoto.concat(this.imgName)
});
// console.log(res);
if (res.code === 200) {
this.$Message["success"]({
background: true,
content: "修改成功"
});
this.$router.push("/goods");
}
}
更多推荐
已为社区贡献8条内容
所有评论(0)