设置个时间 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);
}