$confirm控制台出现Uncaught (in promise) close 和 Uncaught (in promise) cancel

vue $confirm模态框如果想执行取消和关闭后的逻辑,需要在$confirmPromise后跟.catch() 方法。如果没有.catch(),当点击取消或关闭操作时控制台就会出现Uncaught (in promise) closeUncaught (in promise) cancel
.then中执行确定逻辑 .catch 中执行取消和关闭逻辑
代码实现

    handle() {
      this.$confirm("确定此次修改操作", "温馨提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
        closeOnClickModal: false
      }).then((res) => {
        //确定逻辑 点击确定 res='confirm' 
        ...
      }).catch((error) => {
        //取消关闭逻辑 点击取消 error='cancel' 关闭 error='error' 
        ...
      })
    }

async await 写法

    async handle() {
      const confirmResult = await this.$confirm("确定此次修改操作", "温馨提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
        closeOnClickModal: false
      }).then((res)=>res).catch((error) => error)  // .then() 可以不带  
      if (confirmResult === 'confirm') {
       // await 耗时操作方法
      }
       if (confirmResult === 'cancel') {
       //  取消 
      }
       if (confirmResult === 'cancel') {
       //  关闭
      }
      ...
    }
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值