javascript - IE 11 react 'promise' 未定义
问题描述
我正在尝试加载使用 react 构建的页面。当页面加载时,有一个使用反应呈现的表格。此表当前未在 IE 上加载,并抛出错误 promise is not defined。与承诺完全相同的代码适用于其他浏览器。下面是代码。
fetchData(url) {
// Return a new promise.
return new Promise(function (resolve, reject) {
$.ajax(
{
url: url,
cache: false,
context: this,
dataType: 'json', // we're expecting JSON as a response
data: {},
method: "GET",
contentType: "application/json; charset=utf-8",
success: function (data, status, xhr) {
resolve(JSON.parse(data));
},
error: function (xhr, status, httpErrorText) {
reject(httpErrorText);
}
});
});
}
任何想法为什么会发生这种情况以及如何解决这个问题。
解决方案
我遇到过同样的问题。我添加了以下行,public/index.html
其中修复了所有 IE11 polyfill 并且它起作用了:
<script src="https://cdn.polyfill.io/v2/polyfill.min.js?features=es6"></script>
推荐阅读
- java - 编写以枚举和字符串为参数的通用方法
- xml - 使用 XSLT1 有条件地显示来自 XML 的数据?
- project-reactor - 尝试管理多个 Flux/Mono,先开始其中一些,然后合并其中一些,然后有点迷失
- c++ - C++ - std::initializer_list 与 std::span
- r - 使用 gganimate 和 geom_sf 进行颜色填充的问题
- node.js - req.session 不在另一条路线上工作
- python - 爆炸后在熊猫中合并行
- python - 使用 python 的 Git 签出和扫描子目录
- typescript - 尝试将打字稿捆绑到单个文件会产生神秘的垃圾
- reactjs - 上传文件(图片/PDF)并使用 React 预览上传的图片/PDF