-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathreact-9.html
More file actions
53 lines (52 loc) · 1.54 KB
/
react-9.html
File metadata and controls
53 lines (52 loc) · 1.54 KB
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
<!DOCTYPE html>
<html>
<head>
<title>react-生命周期</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</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">
var Button = React.createClass({
getInitialState:function() {
return {data:1};
},
setNewNumber:function(){
this.setState({data:this.state.data+1});
},
componentWillMount:function(){
console.log('1...component will mount');
},
componentDidMount:function(){
console.log('2...component did mount');
},
componentWillUpdate:function(){
console.log('3...component will update');
},
componentDidUpdate:function(){
console.log('4...component did update');
},
componentWilUnmount:function(){
console.log('5...component will unmount');
},
render:function(){
return(
<div>
<button onClick={this.setNewNumber}>Add</button>
<span>{this.state.data}</span>
</div>
)
}
});
ReactDOM.render(
<Button/>,
document.getElementById('app')
)
</script>