-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathreact-5.html
More file actions
39 lines (37 loc) · 936 Bytes
/
react-5.html
File metadata and controls
39 lines (37 loc) · 936 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>react-PropTypes</title>
</head>
<body>
<div id="app"></div>
</body>
</html>
<script src="./js/react.js"></script>
<script src="./js/react-dom.js"></script>
<script src="http://cdn.bootcss.com/babel-core/5.8.38/browser.min.js"></script>
<script type="text/babel">
//propTypes属性就是用来验证组件实例是否复合要求
let MyTitle = React.createClass({
propTypes:{
name:React.PropTypes.string.isRequired
},
getDefaultProps : function() {
return {
name:'Hello world!'
}
},
render:function(){
return <h1>{this.props.name}</h1>
}
});
var title = '123';
ReactDOM.render(
<MyTitle name={title}/>,
// <MyTitle />,
document.getElementById('app')
)
//getDefaultProps 方法可以用来设置组件属性的默认值
</script>