- 为了捕获上一步 then 中的 promise 结果,必须在上一步 return;
- 关闭遮罩层,放在 finally 中,即无论成功或失败都要执行;
archiveAction(actionType, row) {
const ids = row && row.id ? row.id : this.ids;
const tip = row && row.id ? `“${row.projectName}”` : "所勾选的";
const actionLabel = actionType === "archive" ? "归档" : "解档";
this.$modal
.confirm(`是否确认${actionLabel}${tip}项目?${actionLabel}后可编辑`)
.then(async () => {
this.$modal.loading(`正在${actionLabel},请稍后……`);
return actionType === "archive"
? await project.archiveProject(ids)
: await project.unArchiveProject(ids);
})
.then((res) => {
// 这里为了捕获上一步 then 中的 promise 结果,必须在上一步 return
this.$modal.msgSuccess(`${actionLabel}成功`);
this.getList();
})
.catch((err) => {
console.log(err);
})
.finally(() => {
this.$modal.closeLoading();
});
},
标签:const,actionLabel,ids,简易,modal,catch,写法,id,row
From: https://www.cnblogs.com/shayloyuki/p/18298988