-
Notifications
You must be signed in to change notification settings - Fork 51
/
4.生命周期.html
50 lines (46 loc) · 1.41 KB
/
4.生命周期.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
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport"
content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
<script src="node_modules/react/dist/react.js"></script>
<script src="node_modules/react-dom/dist/react-dom.js"></script>
</head>
<!--jsx-->
<body>
<div id="root">
</div>
<script src="node_modules/babel-standalone/babel.js"></script>
<!--jsx 基类 父类 顶层类 -->
<script type="text/babel">
class Time extends React.Component{
constructor(){
super();
this.state={time:0};
console.log("构造函数");
}
/*组件即将装配到页面当中 一个组件从无到有的过程*/
componentWillMount(){
console.log("组件即将装配到页面当中")
}
render(){
console.log("组件正在装配到页面当中")
return <div>{this.state.time}</div>
}
/*组件已经渲染到页面当中*/
componentDidMount(){
var num=0;
setInterval(()=>{
console.log(num);
num++
this.setState({time:num})
},1000)
}
}
ReactDOM.render(<Time/>,document.getElementById("root"))
</script>
</body>
</html>