Vue.js前台报Uncaught (in promise) cancel错误解决办法
微wx笑
2022-07-10【前端开发】
2
0关键字:
vue
注意:是浏览器的开发者工具的控制台输出错误,页面上是感觉不到的。
Vue.js前台报Uncaught (in promise) cancel错误解决办法
下面的代码会报错,
注意:是浏览器的开发者工具的控制台输出错误,页面上是感觉不到的。
handleDelete(row){
var rlt = this.$confirm(`确定删除项目 ${ row.pname }?`);
//console.log(rlt);
if (rlt){
}
},解决方法:
handleDelete(row){
this.$confirm(`确定删除项目 ${ row.pname }?`).then(() => {
//这里是确认后要执行的代码
}).catch(()=>{});
},更多示例
<template>
<el-button type="text" @click="open">点击打开 Message Box</el-button>
</template>
<script>
export default {
methods: {
open() {
this.$confirm('此操作将永久删除该文件, 是否继续?', '提示', {
confirmButtonText: '确定',
cancelButtonText: '取消',
type: 'warning'
}).then(() => {
this.$message({
type: 'success',
message: '删除成功!'
});
}).catch(() => {
this.$message({
type: 'info',
message: '已取消删除'
});
});
}
}
}
</script>调用$confirm方法即可打开消息提示,它模拟了系统的 confirm。Message Box 组件也拥有极高的定制性,我们可以传入options作为第三个参数,它是一个字面量对象。type字段表明消息类型,可以为success,error,info和warning,无效的设置将会被忽略。注意,第二个参数title必须定义为String类型,如果是Object,会被理解为options。在这里我们用了 Promise 来处理后续响应。
本文由 微wx笑 创作,采用 署名-非商业性使用-相同方式共享 4.0 许可协议,转载请附上原文出处链接及本声明。
原文链接:https://www.ivu4e.cn/blog/front/2022-07-10/1298.html



