分析:出现Uncaught (in promise) cancel的原因因为this.$confirm方法内置promise方法不能去掉.catch(),没有.catch取消操作无法捕获.
会报错的用法如下:
async beforeRouteLeave(to, from , next) {
const result = await this.$confirm('配置未生效,请确认是否保存', '提示', {
confirmButtonText: '确定',
cancelButtonText: '取消',
type: 'warning'
}).then(res=>res);
if (result === 'confirm') {
const loadingInstance = Loading.service();
await this.begainSave();
this.$nextTick(() => {
loadingInstance.close();
});
}
next();
}
正确用法如下:要对error
进行catch
async beforeRouteLeave(to, from , next) {
const result = await this.$confirm('配置未生效,请确认是否保存', '提示', {
confirmButtonText: '确定',
cancelButtonText: '取消',
type: 'warning'
}).then(res=>res).catch(error=>error);
if (result === 'confirm') {
const loadingInstance = Loading.service();
await this.begainSave();
this.$nextTick(() => {
loadingInstance.close();
});
}
next();
}