[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]:触发按钮后定时器的值没有变化。提供给我 实现这一目标的最佳方法。