gpt4 book ai didi

javascript - 使用 RequireJS 加载时未定义 React

转载 作者:行者123 更新时间:2023-11-28 17:39:54 25 4
gpt4 key购买 nike

鉴于下面的 JavaScript:

<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/require.js/2.3.5/require.min.js"></script>
<script type="text/javascript">
require.config({
paths: {
'react': 'https://cdnjs.cloudflare.com/ajax/libs/react/16.2.0/umd/react.production.min',
'react-dom': 'https://cdnjs.cloudflare.com/ajax/libs/react-dom/16.2.0/umd/react-dom.production.min'
}
});
require(['react', 'react-dom'], function () {
var x = React;//Error - React is not defined
});
</script>

为什么我在控制台中收到错误React is not Defined

enter image description here

最佳答案

您应该声明您要导入的模块:

requirejs(['react', 'react-dom'], function(React, ReactDOM) { })

这是一个工作示例:https://jsfiddle.net/remarkablemark/mejyoLk6/?utm_source=website&utm_medium=embed&utm_campaign=mejyoLk6

关于javascript - 使用 RequireJS 加载时未定义 React,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48168484/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com