|
|
@@ -0,0 +1,50 @@
|
|
|
+<!DOCTYPE html>
|
|
|
+<html lang="en">
|
|
|
+
|
|
|
+<head>
|
|
|
+ <meta charset="UTF-8">
|
|
|
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
|
+ <title>Document</title>
|
|
|
+ <script src="./babel.min.js"></script>
|
|
|
+ <script src="./react.development.js"></script>
|
|
|
+ <script src="./react-dom.development.js"></script>
|
|
|
+</head>
|
|
|
+
|
|
|
+<body>
|
|
|
+ <div id="root"></div>
|
|
|
+ <script type="text/babel">
|
|
|
+ // setState 更新组件状态state 触发组件重新渲染的核心方法
|
|
|
+ let root = ReactDOM.createRoot(document.getElementById("root"));
|
|
|
+ class Count extends React.Component {
|
|
|
+ constructor(props) {
|
|
|
+ super(props)
|
|
|
+ this.state = {
|
|
|
+ count: 0
|
|
|
+ }
|
|
|
+ }
|
|
|
+ handleClick = () => {
|
|
|
+ // this.setState({
|
|
|
+ // count: 2
|
|
|
+ // })
|
|
|
+ this.setState((state,props) => ({
|
|
|
+ count: state.count + 1
|
|
|
+ }))
|
|
|
+ }
|
|
|
+ render() {
|
|
|
+ return (
|
|
|
+ <div>
|
|
|
+ <h1 onClick={this.handleClick}>{this.state.count}</h1>
|
|
|
+ </div>
|
|
|
+ )
|
|
|
+ }
|
|
|
+ }
|
|
|
+ // function Count() {
|
|
|
+ // return (
|
|
|
+ // <div><h1></h1></div>
|
|
|
+ // )
|
|
|
+ // }
|
|
|
+ root.render(<Count />);
|
|
|
+ </script>
|
|
|
+</body>
|
|
|
+
|
|
|
+</html>
|