【问题标题】:Prevent automatic page refresh with SweetAlert使用 SweetAlert 防止自动页面刷新
【发布时间】:2020-09-30 21:23:46
【问题描述】:

我的网站上有几个页面,它们在使用 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();
          }
        });

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

【问题讨论】:

  • 很确定 SweetAlready 允许使用 await 关键字。尝试使用await Swal.fire({...})
  • 它的意思是我不能在异步函数之外使用 await。
  • 你不能在顶层使用 await。将它包装在一个立即调用的异步函数中。示例:hastebin.com/nowawiwife.js

标签: javascript ruby-on-rails sweetalert actioncable sweetalert2


【解决方案1】:

你可以试试这样的:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-12-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-12-14
    相关资源
    最近更新 更多