我只是使用脚本标签来引入库。引用的例子是使用require。有没有办法避免这种情况?其他库似乎加载正常。
我知道这是折旧但仍然想知道如何让以下示例正常工作:
<!DOCTYPE html>
<html>
<head>
<script crossorigin src="https://cdnjs.cloudflare.com/ajax/libs/babel-standalone/6.26.0/babel.min.js"></script>
<script crossorigin src="https://unpkg.com/react@16/umd/react.development.js"></script>
<script crossorigin src="https://cdn.jsdelivr.net/npm/create-react-class@15.6.2/create-react-class.js"></script>
<script crossorigin src="https://unpkg.com/react-dom@16/umd/react-dom.development.js"></script>
<title>React Example</title>
</head>
<body>
<div id='container'></div>
<script type='text/jsx'>
var HelloComponent2 = React.createClass({
render: function() {
return (
<h1>Hello, classical</h1>
);
}
});
ReactDOM.render(
<HelloComponent2 name='Blobby0' />,
document.getElementById('container')
);
</script>
</body>
</html>
答案 0 :(得分:2)
正如你所说,它被弃用了。使用旧版本的React使该示例有效:
<script crossorigin src="https://cdnjs.cloudflare.com/ajax/libs/react/15.6.1/react.js"></script>
<script crossorigin src="https://cdnjs.cloudflare.com/ajax/libs/react-dom/15.6.1/react-dom.js"></script>