鉴于下面的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
中收到错误?
答案 0 :(得分:3)
您应该声明要导入的模块:
requirejs(['react', 'react-dom'], function(React, ReactDOM) { })