需求:
关闭ElMessageBox提供的弹窗,点击右上角x 不触发catch中的方法。
原本正常的操作就是点关闭按钮就可以了,但我项目中 点取消需要调用接口事件;所以需要加distinguishCancelAndClose: true 进行区分
ElMessageBox.confirm('是否需要通知相关人?', '确认', {
confirmButtonText: '确定',
cancelButtonText: '取消',
type: 'warning',
// 添加自定义类名,用于自定义按钮位置
customClass: 'custom-confirm-dialog',
distinguishCancelAndClose: true
})
.then(() => {
//点击确定触发事件
})
.catch((action) => {
//action 会有close和cancel; close就是点右上角x会触发的方法,我这里是点取消才调接口
if (action === 'cancel') {
//相关逻辑处理
}
})