【elementplus】给确认提示框的确认按钮增加加载状态的写法

const handleDel = (tips = "", delAction, delParams) => {
    
    
    ElMessageBox.confirm(`确定删除该${
      
      tips}吗?`, "提示", {
    
    
      confirmButtonText: "确认",
      cancelButtonText: "取消",
      beforeClose: (action, instance, done) => {
    
    
        if (action === "confirm") {
    
    
          // 开启按钮加载
          instance.confirmButtonLoading = true;
          // 删除接口
          delAction(delParams)
            .then((res: any) => {
    
    
              if (res.code === 200) {
    
    
                ElMessage.success("操作成功");
                getList();
                done();
              }
            })
            .catch(() => {
    
    })
            .finally(() => {
    
    
              // 接口回调结束,关闭按钮加载
              instance.confirmButtonLoading = false;
            });
        } else {
    
    
          done();
        }
      },
    }).catch(() => {
    
    });
  };

猜你喜欢

转载自blog.csdn.net/bbt953/article/details/132384238