【问题标题】:promise is undefined in IE11 when using axios in ReactJS在 ReactJS 中使用 axios 时,在 IE11 中未定义 promise
【发布时间】:2019-08-13 08:39:40
【问题描述】:

我正在将我的反应代码转换为打字稿并使用 axios 进行网络调用。 在 IE11 中运行时出现错误“未定义承诺”

我知道我需要使用 polyfill,但是如何使用?我没有使用 Babel 和 Webpack。

我使用了 babel-polyfill.js,错误消失了,但我得到了这个错误

未捕获的 Sys.ParameterCountException:Sys.ParameterCountException:参数计数不匹配。

知道我该怎么做吗?

tsconfig.json

{
    "compilerOptions": {
        "module": "UMD",
        "removeComments": true,
        "preserveConstEnums": true,
        "sourceMap": true,
        "jsx": "react",
        "lib": ["DOM","ES6","DOM.Iterable","ScriptHost"],
        "typeRoots": []
    },
    "include": [
        "*.tsx"
    ],
    "exclude": [
        "node_modules"        
    ]
}

abc.tsx

import axios = require('../../Scripts/axios');
import * as React from 'react';
import * as ReactDOM from 'react-dom';
class abc extends React.Component<Props, state> {

function renderabc(res){
  ReactDOM.render(
  <abc resources={res}/>,
  document.getElementById('abc_React')
);  
}
export abc;

预期结果:axios 可在 IE11 上运行

【问题讨论】:

    标签: reactjs typescript axios internet-explorer-11


    【解决方案1】:

    axios documentation 指向this polyfill,其中包含有关如何将其包含在您的页面中的说明。

    【讨论】:

    • 我查看了这个文档,我这样做了.. 安装了 npm es6-promise 并将这行代码添加到 axios/lib/core/Axios.js var Promise = require('./.. /../../es6-promise/es6-promise').Promise;我做错了吗?
    • 它有效。我在我的文件夹中添加了 es-promise.js 和 es-promise.auto.js 脚本。
    猜你喜欢
    • 1970-01-01
    • 2013-11-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-11-13
    • 1970-01-01
    • 2020-11-16
    • 1970-01-01
    相关资源
    最近更新 更多