element-ui中用的是 .then .catch 的形式,这个我改成了aysnc/await 形式
具体代码如下
async delParams () {
const confirmRes = await this.$confirm('此操作将永久删除该参数, 是否继续?', '提示', {
confirmButtonText: '确定',
cancelButtonText: '取消',
type: 'warning'
}).catch(err => err)
if (confirmRes !== 'confirm') {
return this.$message.info('已取消删除')
}
const { data: res } = await this.$http.delete(`xxxxx`)
if (res.meta.status !== 200) {
return this.$message.error('删除失败')
}
this.$message.success('删除成功')
this.getDataList()
}
文章展示了如何将Element-UI组件库中的Promise链式调用(.then.catch)转换为async/await语法,用于处理用户确认删除操作和HTTP删除请求。在转换后,代码的可读性和异步控制更清晰。

6507

被折叠的 条评论
为什么被折叠?



