当点击switch按钮之前,如果当更新后再刷新的效果不好,需要判断行为,然后再决定是否打开按钮。
正确如下:
return new Promise((resolve,reject) => {
ElMessageBox.confirm('Hold?', 'Warning', {
confirmButtonText: 'Yes',
cancelButtonText: 'No',
type: 'warning'
})
.then(() => {
ElMessage.success('Switch success')
return resolve(true)
})
.catch(() => {
ElMessage.success('Hold Cancel')
return reject(new Error('Error'))
})
})
错误示例如下:
ElMessageBox.confirm('Release Hold?', 'Warning', {
confirmButtonText: 'Yes',
cancelButtonText: 'No',
type: 'warning'
})
.then(() => {
ElMessage.success('Release Switch success')
isOpen.value = true
})
.catch(() => {
return new Promise((resolve, reject) => {
ElMessage.success('Release Cancel')
isOpen.value = false
})
})