zoukankan      html  css  js  c++  java
  • react实例7-时钟

    <!doctype html>
    <html>
    <head>
    <meta charset="UTF-8">
    <title>test01</title>
    <script src="build/browser.min.js"></script>
    <script src="build/react.js"></script>
    <script src="build/react-dom.js"></script>
    <script type="text/babel">
    class Clock extends React.Component{
    constructor(...args){
    super(...args);

    this.state={
    h:0,
    m:0,
    s:0
    }

    var _this=this;
    setInterval(function(){
    _this.tick();
    },1000);

    }

    componentDidMount(){
    this.tick();
    }

    tick(){
    var oDate=new Date();
    this.setState({
    h:oDate.getHours(),
    m:oDate.getMinutes(),
    s:oDate.getSeconds(),
    });
    }

    render(){
    return <div>
    <span>{this.state.h}</span>:
    <span>{this.state.m}</span>:
    <span>{this.state.s}</span>
    </div>
    }


    }


    window.onload=function(){
    ReactDOM.render(
    <Clock/>,
    document.getElementById('app'),function(){
    console.log("渲染成功啦")
    }
    );
    }
    </script>
    </head>

    <body>
    <div id="app"></div>


    </body>
    </html>

  • 相关阅读:
    bzoj2818
    bzoj1901
    bzoj1010
    loj6277
    bzoj1001
    bzoj1787
    选项卡
    日期选择器
    去掉文本框的外边框
    bootstarp 模态框大小尺寸的控制
  • 原文地址:https://www.cnblogs.com/codepen2010/p/6853065.html
Copyright © 2011-2022 走看看