Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/406.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript SweetAlert2不';I don’我不能在IE 11上工作,承诺没有定义_Javascript_Internet Explorer_Promise_Sweetalert2 - Fatal编程技术网

Javascript SweetAlert2不';I don’我不能在IE 11上工作,承诺没有定义

Javascript SweetAlert2不';I don’我不能在IE 11上工作,承诺没有定义,javascript,internet-explorer,promise,sweetalert2,Javascript,Internet Explorer,Promise,Sweetalert2,我正在使用SweetAlert2和IE 11抛出异常: 此软件包需要Promise库,请包含一个垫片以 在此浏览器中启用它(请参见: ) 因为IE 11不支持承诺,需要手动添加 我用的是蓝知更鸟,就像这样: const Promise = require('bluebird'); const Swal = require('sweetalert2'); Swal.fire(...) ... 但是,sweetalert的支票还是没有通过: .. if (typeof Promise ===

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

此软件包需要Promise库,请包含一个垫片以 在此浏览器中启用它(请参见: )

因为IE 11不支持承诺,需要手动添加

我用的是蓝知更鸟,就像这样:

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(...);

对于直接使用Sweetalert2的用户,请在页面中引用:

这也可以通过在Sweetalert2 lib之后包含以下核心js lib来解决

<script src="https://cdnjs.cloudflare.com/ajax/libs/core-js/2.4.1/core.js"></script>


尝试将
添加到您的html。我需要使用require添加它,我已经添加了bluebird polyfill。为什么需要添加?你发布的文档,字面意思是为IE添加脚本。因为我不想在页面上添加额外的资源,我使用sweetalert2有30多个页面/资源,我需要检查每一个htmls并添加这个。然后将javascript放入一个文件并导出它?这不一定很难。。。