forked from selfRepositoryAll/Source-code-analysis-react
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathreact.html
75 lines (70 loc) · 1.87 KB
/
react.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
71
72
73
74
75
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<script src="./react.js"></script>
<script src="./react-dom_1.js"></script>
<script src="https://npmcdn.com/babel-core@5.8.38/browser.min.js"></script>
<script src="./babel.js"></script>
</head>
<body>
<pre>
http://www.cnblogs.com/sunshine-anycall/p/5950650.html
</pre>
<div id="example"></div>
<script type="text/babel">
// var ChildLeft= React.createClass({
// render(){
// return(
// <div>childLeft</div>
// )
// }
// })
// var ChildRight= React.createClass({
// render(){
// return(
// <div>childRight</div>
// )
// }
// })
class HelloMessage extends React.Component{
constructor(props) {
super(props)
this.state={
age:10
}
}
// componentWillUpdate(a,b,c){// 看一下都传了什么参数
// console.log('componentWillUpdate')
// }
componentDidMount(){
console.log('componentDidMount')
}
handleEvent(){
this.setState({
age:11
});
}
render(){
return (
<div ref='eee'>
<h1>{this.state.age}</h1>
<button onClick={()=>this.handleEvent()} >button</button>
</div>
)
}
}
ReactDOM.render(
<HelloMessage name="John" />,
document.getElementById('example')
);
</script>
</body>
</html>
<script>
/* 讲这个对象全部缓存到 ReactClassComponent的私有属性上
<h1>{this.state.age}</h1> 当执行render的时候我们已经 state 更新完成了 同时 创建元素的时候
children 就是标签内部的内
*/
</script>