如何在reactjs中制作秒表应用程序?

时间:2018-03-23 13:34:21

标签: stopwatch

[1]如何在reactjs中制作像https://www.online-stopwatch.com/countdown/这样的秒表应用程序......?

import React,{Component} from 'react';

export default class StopWatch extends Component{
  constructor(props){
    super(props);
    this.state={
      time2: ''
    }
  }
  timeCount(){
    this.time= setInterval(() => {
      this.setState({ time2:this.state.time2 - 1});
    },1000);
  }
  stopTimer() {
    clearInterval(this.time);
  }
  componentDidUpdate(){
    console.log(this.state.time2);
    if(this.state.count===0){
      clearInterval(this.time);
    }
  }
  componentWillUnmount(){
    clearInterval(this.time);
  }

  toggle(key){
    if(this.state.time2.length < 6) {
      this.setState({ time2: `${this.state.time2}` + `${key}` });
    }
  }

[2]:触发按钮后定时器的值没有变化。提供给我      实现这一目标的最佳方法。

参考链接:https://www.online-stopwatch.com/countdown/

0 个答案:

没有答案