Sweetalert Promise 问题

Sweetalert Promise issue

正在寻找但找不到任何答案。

我遇到了 Promise() 问题。

一直在使用 Sweetalert,所以创建了一个脚本:

<button onclick="showAlert();">some button</button>
<script> 
/**
 * @constuctor
*/
function Obj() { };

/**
 * @method getInst
 * @param arguments
 */
Obj.prototype.getInst = function () {
  swal.apply(this, arguments);
};

/**
 * @instance
 */
var newInst = new Obj();

function showAlert() {
  newInst.getInst({
    title: "Good job!",
    text: "You clicked the button!",
    icon: "success"
  });
};

并将参数应用于 swal 对象工作正常。然而,应用回调与承诺(Sweetalert 以这种方式工作)不能链接并应用于对象并且不起作用:

function showAlert() {
  newInst.getInst("Click on either the button or outside the modal.")
  .then((value) => {
  swal(`The returned value is: ${value}`);
});
};

感谢您的回复。

好的,完成了。

如果有人感兴趣,您只需将 Sweet Alert 对象直接传递给构造函数即可:

Obj.prototype.getInst = function () {
  swal(opts);
};