javascript - SweetAlert2 不适用于 IE 11,未定义 Promise

标签 javascript internet-explorer promise sweetalert2

我正在使用 SweetAlert2,在 IE 11 上抛出异常:

This package requires a Promise library, please include a shim to enable it in this browser (See: https://github.com/sweetalert2/sweetalert2/wiki/Migration-from-SweetAlert-to-SweetAlert2#1-ie-support)

因为IE 11不支持Promises,需要手动添加。

我像这样使用 bluebird :

const Promise = require('bluebird');
const Swal = require('sweetalert2');

Swal.fire(...)
...

但是,sweetalert 的检查仍然没有通过:

..
  if (typeof Promise === 'undefined') {
    error('This package requires a Promise library, please include a shim to enable it in this browser (See: https://github.com/sweetalert2/sweetalert2/wiki/Migration-from-SweetAlert-to-SweetAlert2#1-ie-support)');
  }
..

如何解决?谢谢。

最佳答案

您可以使用以下方法修复它:

window.Promise = require('bluebird');

这会将 Promise 作为窗口的全局变量加载,而不是像使用 const 那样加载文件。

我不确定你的文件结构如何,但如果你有一个加载所有依赖项的文件,你可以简单地将上面的行添加到将在其他脚本之前调用的脚本中。

例如:

// bootstrap.js
window.Promise = require('bluebird');
window.Swal = require('sweetalert2');

// app.js
require('./bootstrap');
Swal.fire(...);

关于javascript - SweetAlert2 不适用于 IE 11,未定义 Promise,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55575665/

相关文章:

javascript - Highcharts:动态调整实心仪表图的大小

javascript - (IE 特定)如何确定输入的文本是否比输入元素的宽度长

javascript - 如何为 Promise.all 参数映射字符串数组?

javascript - 从网络计算机上启用智能卡的登录中读取 Windows 用户名

css - Internet 浏览器 CSS : Joomla Custom template

javascript - 如何在 Node.js 中通用化 http 响应处理程序?

javascript - Backbone Model.save 返回未定义而不是 jqxhr

javascript - 如何在网页上以编程方式模糊文本并使其不可读

javascript - 如何使用相同的键聚合 2 个 json 数组的所有列

javascript - 当每个 div 滚动到 View 和更新状态时触发事件