-
Notifications
You must be signed in to change notification settings - Fork 0
/
react_demo07.html
49 lines (48 loc) · 1.62 KB
/
react_demo07.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
<!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>生命周期</title>
<link rel="stylesheet" href="css/style.css">
<script src="./common/react.js"></script>
<script src="./common/react-dom.js"></script>
<script src="https://cdn.bootcss.com/babel-core/5.8.38/browser.js"></script>
</head>
<body>
<div id="reactContainer"></div>
<script type="text/babel">
var AddCount = React.createClass({
getInitialState:function () {
console.log('1.getInitialState');
return {count:1}
},
componentWillMount:function () {
console.log('2.componentWillMount')
},
componentDidMount:function () {
console.log('3.componentDidMount')
},
componentWillUpdate:function () {
console.log('4.componentWillUpdate')
},
componentDidUpdate:function () {
console.log('5.componentDidUpdate')
},
handleClick:function () {
this.setState({count:this.state.count+1})
},
render:function () {
return (
<p>
{this.state.count}<br/>
<button onClick={this.handleClick}>Add</button>
</p>
)
}
})
ReactDOM.render(<AddCount/>,document.getElementById("reactContainer"))
</script>
</body>
</html>