6

现在我有这个代码:

swal({
     title: 'Loading cars from data base',
     showLoaderOnConfirm: true,
     preConfirm: () => {
       return this.carsSvc.getCars().then((cars: ICar[]) => {
               this.setData(cars);
               resolve();
            });
    }
});

此代码显示一个警报,我必须按“确认”,然后它会显示一个加载图标并在加载完成时关闭。我只想要这个动作的最后一部分,所以我不想在开始加载之前确认加载。我希望在打开警报时开始加载,并在加载完成后自动关闭。SweetAlert2有可能吗?

4

3 回答 3

16

你也可以用这个

            Swal.fire({
                title: 'Please Wait !',
                html: 'data uploading',// add html attribute if you want or remove
                allowOutsideClick: false,
                onBeforeOpen: () => {
                    Swal.showLoading()
                },
            });

并关闭它

swal.close();
于 2020-04-20T09:38:16.510 回答
15

可能有点晚了,但我想通了。尝试这个:

swal({
     title: 'Loading cars from data base'
});
swal.showLoading();

this.carsSvc.getCars().then((cars: ICar[]) => {
           swal.close();
           this.setData(cars);
           // show a new success swal here?
        });

您想调用该swal.showLoading()方法来禁用按钮。然后你可以打电话swal.close()完成。

于 2017-11-02T06:38:19.730 回答
7

你可以试试用这个...

Swal.fire({
  title: 'Uploading...',
  html: 'Please wait...',
  allowEscapeKey: false,
  allowOutsideClick: false,
  didOpen: () => {
    Swal.showLoading()
  }
});
于 2021-06-10T19:41:09.467 回答