你是否遇到过,使用ElMessageBox.confirm组件时,当接口报错的时候,弹出两个提示?

废话不说,上图 👇

代码如下
ElMessageBox.confirm('是否删除该条数据', '提示', {
confirmButtonText: '确定',
cancelButtonText: '取消',
type: 'warning'
})
.then(async () => {
await delData(ids)
})
.catch(() => {
ElMessage({
type: 'error',
message: '取消成功'
})
})
优化代码如下(解决)
ElMessageBox.confirm('是否删除该条数据', '提示', {
confirmButtonText: '确定',
cancelButtonText: '取消',
type: 'warning'
})
.then(async () => {
try {
await delData(ids)
} catch {}
})
.catch(() => {
ElMessage({
type: 'error',
message: '取消成功'
})
})