-
-
Notifications
You must be signed in to change notification settings - Fork 65
/
Copy pathsetState.html
54 lines (49 loc) · 1.38 KB
/
setState.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
<!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>Document</title>
</head>
<body>
<div id="demo">
</div>
<script src="../js/react.js"></script>
<script src="../js/react-dom.js"></script>
<script src="../js/babel.js"></script>
<!-- ES6 JSX -->
<script type="text/babel">
class Xbtn extends React.Component {
constructor(props){
super(props)
// 父传子 老爸给我的
this.props = props;
// 自己拥有的 就是vue组件里面data Model
this.state = {
"title":"微信"
};
}
changeValue(){
console.log(this);
this.setState({
"title":"支付宝"
})
}
// view
render() {
return <button onClick={
this.changeValue.bind(this)
}>{this.state.title}</button>;
}
}
ReactDOM.render(
<div>
<input type="password" />
<Xbtn name="btn" />
</div>,
document.querySelector("#demo")
)
</script>
</body>
</html>