首页 > 其他 > 详细

react-conponent-secondesElapsed

时间:2016-02-23 13:17:36      阅读:179      评论:0      收藏:0      [点我收藏+]
<!DOCTYPE html>
<html>
  <head>
    <script src="../../build/react.js"></script>
    <script src="../../build/react-dom.js"></script>
    <script src="../../build/browser.min.js"></script>
  </head>
  <body>
    <div id="example"></div>
    <script type="text/babel">
      var Timer = React.createClass({
        getInitialState : function(){
          return {secondsElapsed:0};
        },

        tick : function(){
          this.setState({secondsElapsed:this.state.secondsElapsed + 1});
        },

        componentDidMount : function(){
            this.interval = setInterval(this.tick,1000);
        },

        componentWillUnmount : function(){
          clearInterval(this.interval);
        },

        render : function(){
          return (
            <div>secondsElapsed:{this.state.secondsElapsed}</div>
          )
        },
      });

      ReactDOM.render(
        <Timer />,
        document.getElementById(‘example‘)
      );
    </script>
  </body>
</html>

  

react-conponent-secondesElapsed

原文:http://www.cnblogs.com/cynthia-wuqian/p/5209437.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!