美文网首页
element-ui报错:Uncaught (in promis

element-ui报错:Uncaught (in promis

作者: RadishHuang | 来源:发表于2020-06-22 12:17 被阅读0次

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

相关文章

网友评论

      本文标题:element-ui报错:Uncaught (in promis

      本文链接:https://www.haomeiwen.com/subject/nejxfktx.html