1:可以先学习React框架,http://www.runoob.com/react/react-tutorial.html
2:减少Html文件的代码,可以将react的代码放到外部的js文件中
3:html代码
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width,
initial-scale=1.0,
maximum-scale=1.0,
user-scalable=no">
<script src="https://cdn.bootcss.com/react/15.4.2/react.min.js"></script>
<script src="https://cdn.bootcss.com/react/15.4.2/react-dom.min.js"></script>
<script src="https://cdn.bootcss.com/babel-standalone/6.22.1/babel.min.js"></script>
<title>Home</title>
</head>
<body>
<div id="example">
</div>
<script type="text/babel" src="HomeJs.js"></script>
</body>
</html>
注意
<script type="text/babel" src="HomeJs.js"></script>
这句话的type="text/babel"是为了调用jsx,一定需要
4:js代码
var WebSite = React.createClass({
render: function() {
return (
<div>
<h1>{this.props.name}</h1>
<a href={this.props.site}>
{this.props.site}
</a>
</div>
);
}
});
var Name = React.createClass({
render: function() {
return (
<h1>{this.props.name}</h1>
);
}
});
var Link = React.createClass({
render: function() {
return (
<a href={this.props.site}>
{this.props.site}
</a>
);
}
});
ReactDOM.render(
<WebSite name="sssss" site="http://baidu.com" />,
document.getElementById('example')
);
网友评论