|
@@ -0,0 +1,64 @@
|
|
|
|
|
+<!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">
|
|
|
|
|
+ let root = ReactDOM.createRoot(document.getElementById("root"));
|
|
|
|
|
+ function App() {
|
|
|
|
|
+ return (
|
|
|
|
|
+ <div>
|
|
|
|
|
+ <Flower />
|
|
|
|
|
+ </div>
|
|
|
|
|
+ )
|
|
|
|
|
+ }
|
|
|
|
|
+ class Flower extends React.Component {
|
|
|
|
|
+ constructor(props) {
|
|
|
|
|
+ super(props);
|
|
|
|
|
+ this.state = {
|
|
|
|
|
+ currentTime: new Date(),
|
|
|
|
|
+ count: 0
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ // 挂载
|
|
|
|
|
+ componentDidMount() {
|
|
|
|
|
+ console.log("挂载");
|
|
|
|
|
+ this.timer = setInterval(() => {
|
|
|
|
|
+ this.setState((state, props) => {
|
|
|
|
|
+ currentTime: new Date();
|
|
|
|
|
+ count: 2
|
|
|
|
|
+ })
|
|
|
|
|
+ }, 1000)
|
|
|
|
|
+ }
|
|
|
|
|
+ // 更新
|
|
|
|
|
+ componentDidUpdate() {
|
|
|
|
|
+ console.log("更新")
|
|
|
|
|
+ }
|
|
|
|
|
+ // 卸载
|
|
|
|
|
+ componentWillUnMount() {
|
|
|
|
|
+ clearInterval(this.timer);
|
|
|
|
|
+ }
|
|
|
|
|
+ render() {
|
|
|
|
|
+ return (
|
|
|
|
|
+ <div>
|
|
|
|
|
+ <h1>类组件</h1>
|
|
|
|
|
+ <h2>{this.state.count}</h2>
|
|
|
|
|
+ <h3>{this.state.currentTime.toLocaleString()}</h3>
|
|
|
|
|
+ </div>
|
|
|
|
|
+ )
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ root.render(<App />);
|
|
|
|
|
+ </script>
|
|
|
|
|
+</body>
|
|
|
|
|
+
|
|
|
|
|
+</html>
|