// 处理异常:
// 所有异步操作原则上来讲都需要处理异常
// 方案1: try - catch (需要嵌套一层)
// try {
// const result = await this.$confirm('确定删除该角色吗?', '提示', {
// type: 'warning'
// })
// console.log(result) // confirm
// } catch (e) {
// console.log(e) // cancel
// }
// 方案2: await 结合 .catch 处理
await 语法糖获取的返回值就是 promise 对象 .then 第一个回调函数中的第一个参数
const result = await this.$confirm('确定删除该角色吗?', '提示', {
type: 'warning'
})
// // .catch(e => {}) // 没有返回结果, 所以返回值是 undefined
.catch(e => e) // 返回值是 e, e 是 cancel
// // 处理异常前: 点确定 confirm, 点取消报错
// // 需求: 知道用户点的是确定还是取消?
// // 在 promise 的串行任务中, 每一次回调函数(包括 .then 和 .catch)中返回的结果, 会作为下一个 .then 的参数
// // 希望点击确定打印 confirm, 点击取消打印 cancel
// console.log(result)