美文网首页
react native 倒计时

react native 倒计时

作者: 以德扶人 | 来源:发表于2017-10-02 22:36 被阅读120次

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

相关文章

网友评论

      本文标题:react native 倒计时

      本文链接:https://www.haomeiwen.com/subject/idxxyxtx.html