設置個時間 indexTime:3
countTime(){
this._timer=setInterval(()=>{this.setState({indexTime:this.state.indexTime -1}); if(this.state.indexTime<=0){
this._timer && clearInterval(this._timer);
}},1000);
}
直接調用countTime();
結束的時候清理一下就行了
componentWillUnmount() {
this._timer && clearInterval(this._timer);
}