async delRow() {
console.log(this.multipleSelection2)
if (this.multipleSelection2.length > 0) {
let selectData = this.multipleSelection2
let milestoneNames = ""
for (let i = 0; i < selectData.length; i++) {
//如果有合同id,去判断该里程碑是否已被关联
if (selectData[i].contract_id != null) {
let result = await this.checkRelevance(selectData[i].id)
console.log("delRow -> result", result)
if (result != null) {
if (result) {
if (milestoneNames === "") {
milestoneNames = milestoneNames + selectData[i].receive_name
} else {
milestoneNames = milestoneNames + "," + selectData[i].receive_name
}
}
}
}
}
if (milestoneNames != "") {
this.$message.warning({
message: "里程碑【" + milestoneNames + "】已被关联不能删除!"
})
return
}
for (let i = 0; i < this.multipleSelection2.length; i++) {
for (let j = 0; j < this.dataTable.length; j++) {
if (this.multipleSelection2[i].index === this.dataTable[j].index) {
this.dataTable.splice(j, 1);
}
}
}
} else {
this.$message.warning({
message: "请选择后再执行删除"
});
}
},
//根据里程碑id去检验是否已被关联
async checkRelevance(id) {
let result = await this.axiosHelper.get('/v0.1/api/contract/checkRelevance/' + id)
.then(res => {
console.log("checkRelevance -> res.data", res.data)
return res.data
})
.catch(error => {
this.$message.error(
"校验里程碑失败"
)
error
return null
})
return result
},
JavaScript异步(async/await):得到请求结果并使用
于 2020-03-24 16:24:28 首次发布
本文详细介绍了JavaScript中的async/await语法,如何利用它们处理异步操作,实现优雅的错误处理,并通过实例展示了如何从API请求中获取并使用数据。通过对异步流程的控制,提升代码可读性和维护性。
摘要由CSDN通过智能技术生成