element-ui报错:Uncaught (in promis

2020-06-22  本文已影响0人  RadishHuang

分析:出现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();
  }
上一篇 下一篇

猜你喜欢

热点阅读