Luk*_* Vo 4 javascript dialog sweetalert2
抱歉,如果我在文档中遗漏了某些内容,但我无法找到阻止在 SweetAlert 2 中关闭对话框的方法,这些将不起作用:
await Swal.fire({
html: diagHtml,
showCancelButton: true,
willClose: (el) => {
console.log(el);
if (someLogic()) {
event.preventDefault();
return false;
}
},
});
Run Code Online (Sandbox Code Playgroud)
有没有办法让对话框保持不变,最好是使用async?
不,你不能阻止对话框用 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
}
},
});
Run Code Online (Sandbox Code Playgroud)