【问题标题】:Prevent SweetAlert2 from closing/dismissing from willClose?防止 SweetAlert2 从 willClose 中关闭/解除?
【发布时间】:2020-10-31 10:52:26
【问题描述】:

抱歉,如果我在文档中遗漏了一些内容,但无论如何我都找不到阻止在 SweetAlert 2 中关闭对话框的方法,这些将不起作用:

        await Swal.fire({
            html: diagHtml,
            showCancelButton: true,

            willClose: (el) => {
                console.log(el);

                if (someLogic()) {
                    event.preventDefault();
                    return false;
                }
            },
        });

有没有办法让对话保持不变,最好是async

【问题讨论】:

    标签: javascript dialog sweetalert2


    【解决方案1】:

    不,您不能使用 willClose 阻止对话框关闭,也许以下代码可以替代您:

    await Swal.fire({
      html: diagHtml,
      showDenyButton: true,
      allowOutsideClick: false,
      allowEscapeKey: false,
      preConfirm: () => {
        if (someLogic()) {
          return false; // Prevent confirmed
        }
      },
      preDeny: () => {
        if (someLogic()) {
          return false; // Prevent denied
        }
      },
    });
    

    【讨论】:

    • 啊,谢谢!我没有注意到这两个选项。会尝试告诉你它是否有效。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-10-26
    • 2015-05-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多