在使用element-ui 的 MessageBox 组件时,可能会用到这个,这里直接根据用户点击“确定”还是“取消”来决定接下来的处理流程:
this.$confirm('此操作将永久删除该文件, 是否继续?', '提示', {
confirmButtonText: '确定',
cancelButtonText: '取消',
type: 'warning'
}).then(() => {
// 用户点击了“确定”按钮后的逻辑
this.$message({
type: 'success',
message: '删除成功!'
});
}).catch(() => {
// 用户点击了“取消”按钮后的逻辑
this.$message({
type: 'info',
message: '已取消删除'
});
});
这两句代码的作用是自定义确认对话框中的按钮文本,使界面更符合中文用户的习惯和需求。通过设置这些属性,可以提升用户体验,确保用户能够清晰地理解每个按钮的功能。
this.$confirm('检测到电脑尚未安装xxx插件,是否跳转到下载页面下载?', '提示', {
confirmButtonText: '确定',
cancelButtonText: '取消',
type: 'warning'
}).then(() => {
window.open('http://www.xxx.html', '_blank')
}).catch(() => {})