onDelete(id){
const res = this.$confirm('此商品将永久删除该文件, 是否继续?', '提示', {
confirmButtonText: '确定',
cancelButtonText: '取消',
type: 'warning'
})
console.log(res)
}
- 打印可知是一个Promise
- 可用async和await优化,错误处理有两种方式
- 第一种通过.catch返回
- 第二种通过同步的try{}catch{}
//方法一
async onDelete(id){
const res = await this.$confirm('此商品将永久删除该文件, 是否继续?', '提示', {
confirmButtonText: '确定',
cancelButtonText: '取消',
type: 'warning'
}).catch(err=>err)
console.log(res)
}
//方法二
async onDelete(id) {
try {
const res = await this.$confirm('此商品将永久删除该文件, 是否继续?', '提示', {
confirmButtonText: '确定',
cancelButtonText: '取消',
type: 'warning'
})
}
catch(err){
console.log(err)
}
}