向 livewire 发送请求时向 sweetalert 添加加载
Add loading to sweetalert when send request to livewire
我在下面写了我的代码,它工作正常,并且正确收到了答案。但问题是当点击确认按钮时,sweetalert 关闭
我希望在请求完全执行并显示加载按钮之前不关闭 sweetalert。我看到了很多关于此的问题,但它们与 ajax 有关,我无法为 livewire
创建它们
document.addEventListener('DOMContentLoaded', function () {
$('.eg-swal-av3').on("click", function (e) {
Swal.fire({
title: 'title',
text: "content",
icon: 'info',
showCancelButton: true,
confirmButtonText: 'بله ایجاد کن',
cancelButtonText : 'لغو',
}).then(function (result) {
if (result.value) {
@this.call('createRequest');
}
});
e.preventDefault();
});
});
您正在寻找接受回调的 preConfirm
属性。这是您 运行 调用您的 createRequest
.
的地方
我还会在加载时添加一个 allowOutsideClick
为真,以便在整个请求过程中都可以看到警报。
Swal.fire({
title: 'title',
text: "content",
icon: 'info',
showCancelButton: true,
confirmButtonText: 'بله ایجاد کن',
cancelButtonText : 'لغو',
allowOutsideClick: () => !Swal.isLoading(),
preConfirm: function(result) {
if (result) {
return @this.call('createRequest').then(() => {
Swal.fire('Loading complete');
});
}
},
});
我在下面写了我的代码,它工作正常,并且正确收到了答案。但问题是当点击确认按钮时,sweetalert 关闭
我希望在请求完全执行并显示加载按钮之前不关闭 sweetalert。我看到了很多关于此的问题,但它们与 ajax 有关,我无法为 livewire
创建它们document.addEventListener('DOMContentLoaded', function () {
$('.eg-swal-av3').on("click", function (e) {
Swal.fire({
title: 'title',
text: "content",
icon: 'info',
showCancelButton: true,
confirmButtonText: 'بله ایجاد کن',
cancelButtonText : 'لغو',
}).then(function (result) {
if (result.value) {
@this.call('createRequest');
}
});
e.preventDefault();
});
});
您正在寻找接受回调的 preConfirm
属性。这是您 运行 调用您的 createRequest
.
我还会在加载时添加一个 allowOutsideClick
为真,以便在整个请求过程中都可以看到警报。
Swal.fire({
title: 'title',
text: "content",
icon: 'info',
showCancelButton: true,
confirmButtonText: 'بله ایجاد کن',
cancelButtonText : 'لغو',
allowOutsideClick: () => !Swal.isLoading(),
preConfirm: function(result) {
if (result) {
return @this.call('createRequest').then(() => {
Swal.fire('Loading complete');
});
}
},
});