-
Notifications
You must be signed in to change notification settings - Fork 2
/
index.html
70 lines (65 loc) · 1.89 KB
/
index.html
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Hello PropTypes</title>
<script src="https://cdn.staticfile.org/react/16.4.0/umd/react.development.js"></script>
<script src="https://cdn.staticfile.org/react-dom/16.4.0/umd/react-dom.development.js"></script>
<script src="https://cdn.staticfile.org/babel-standalone/6.26.0/babel.min.js"></script>
<script src="https://cdn.bootcss.com/prop-types/15.7.2/prop-types.min.js"></script>
</head>
<body>
<p>
<pre>注意:
自 React v15.5 起,React.PropTypes 已移入另一个包中。请使用 prop-types 库 代替。
<a href="https://react.docschina.org/docs/typechecking-with-proptypes.html">使用 PropTypes 进行类型检查</a>
</pre>
</p>
<div id="root"></div>
<div id="root2"></div>
<script type="text/babel">
var data = {
tilte: 'Hello',
age: 19,
isStudent: true,
};
class MyTitle extends React.Component {
static propTypes = {
tilte: PropTypes.string,
age: PropTypes.number,
isStudent: PropTypes.bool,
}
render() {
return (
<div>
<h1>{this.props.data.tilte}</h1>
<h2>{this.props.data.age}</h2>
<h3>{this.props.data.isStudent ? 'Yes' : 'No'}</h3>
</div>
);
}
}
ReactDOM.render(
<MyTitle data={data} />,
document.getElementById('root')
)
class DefaultTitle extends React.Component {
constructor(props) {
super(props);
}
static defaultProps = {
title: 'Hello React!',
}
render() {
return <h4>{this.props.title}</h4>;
}
}
ReactDOM.render(
<DefaultTitle />,
document.getElementById('root2')
)
</script>
</body>
</html>