【问题标题】:Add loading to sweetalert when send request to livewire向 livewire 发送请求时向 sweetalert 添加加载
【发布时间】:2021-11-05 23:32:41
【问题描述】:

我在下面编写了我的代码,它可以正常工作并且正确收到了答案。但问题是当点击确认按钮时,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();
    });
});

【问题讨论】:

    标签: javascript laravel-livewire sweetalert


    【解决方案1】:

    您正在寻找接受回调的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');
                });
            }
        },
    });
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-04-17
      • 2023-04-05
      • 2012-06-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-04-01
      相关资源
      最近更新 更多