1 回答
TA贡献1788条经验 获得超4个赞
您的代码中有几个拼写错误:
React.component
应该React.Component
ReactDomFactories
是ReactDOMFactories
(你猜对了h2
:))ReactDom.render
实际上是ReactDOM.render
<head>
<meta charset="UTF-8">
<title>First Component</title>
<script crossorigin src="https://unpkg.com/react@16/umd/react.development.js"></script>
<script crossorigin src="https://unpkg.com/react-dom@16/umd/react-dom.development.js"></script>
<script crossorigin src="https://unpkg.com/react-dom-factories@1.0.0/index.js"></script>
</head>
<body>
<div id="app"></div>
<h1>Hello</h1>
<script type="text/javascript">
class Pet extends React.Component{
render (){
const h2 = ReactDOMFactories.h2(null, "Potter");
const img = ReactDOMFactories.img({src:"https://upload.wikimedia.org/wikipedia/commons/thumb/6/6e/Indian_spitz_adult.JPG/640px-Indian_spitz_adult.JPG",
alt:"Potter my dog"});
return ReactDOMFactories.div(null, h2,img);
}
}
ReactDOM.render(React.createElement(Pet),document.getElementById("app"));
</script>
</body>
添加回答
举报