3

我在这里做错了什么?

swal({
    title: "Done.",
    text: "Labels Printed.",
    timer: 1000,
    type: "success",
    showConfirmButton: false

}).then(function () {

    alert('done');

});

警报没有被触发,我是否需要以某种方式捕捉“计时器”?(警报只是一个例子,我实际上是在这里清除我的表格。)

另外,我如何摆脱 textLabels:1 Uncaught (in promise) 计时器错误?

我正在使用.done()

有人可以为 SweetAlert2 添加标签吗?我没有这样做的声誉。

米克

当我不希望之后发生任何事情时,我需要做什么?:

swal({
    title: "Error.",
    text: "Authorisation Failed.",
    timer: 1000,
    type: "error",
    showConfirmButton: false
}).then(
    function() {}

 )

像这样?:

}).then(
        function() {},
        function() {}
       )
4

1 回答 1

6

更新(17.11.2017):

v7.0.0开始, SweetAlert2 的工作方式与问题启动器的预期完全相同:)


SweetAlert2 使用承诺。每个承诺都可以解决拒绝,您可以这样处理:

swal(…).then(
  function () {
    // handle resolve (confirm button)
  }, 
  function (dismiss) {
    // handle reject, dismiss can be  'cancel', 'overlay', 'close', and 'timer'
  }
)

通过计时器关闭模式被视为拒绝承诺,因此您应该像这样处理它:

Swal.fire({
  title: 'Auto close alert!',
  text: 'I will close in 2 seconds.',
  timer: 2000
}).then(function() {
  alert('done');
})
<script src="https://cdn.jsdelivr.net/npm/sweetalert2@11"></script>

于 2016-11-02T13:09:41.297 回答