防止使用SweetAlert自动刷新页面

问题描述

我的网站上有几个页面,这些页面在使用javascript或有时使用Turbolink甚至是动作电缆功能后刷新页面

我想使用SweetAlert来显示信息,但是它并不是很有用,因为它在刷新之前就显示了,因此只能在短时间内看到。

基于先前的堆栈溢出问题,我构建了这个问题:

      Swal.fire({
        title: 'Sweet!',text: `You got the ${data.badge.description} badge!`,imageUrl: data.badge_image_url,imageWidth: 200,imageHeight: 200,imageAlt: 'Custom image'
        },function(isConfirm) {
          if (isConfirm) {
            window.location.reload();
          }
        });

但是,它似乎无法解决问题。

解决方法

您可以尝试这样的事情:

Swal.fire({
  title: 'Your message',icon: 'info',confirmButtonText: 'OK'
}).then(function(){
  window.location.reload();
})