React 60s倒计时

this.state = {
    btnText: '获取验证码',
    timer: 5,
    discodeBtn: false,
    clearInterval: false
}
let siv = setInterval(() => {
    this.setState({ timer: (timer--), btnText: timer, discodeBtn: true }, () => {
        if (timer === 0) {
            clearInterval(siv);
            this.setState({ btnText: '重新发送', discodeBtn: false })
        }
    });
}, 1000);

猜你喜欢

转载自www.cnblogs.com/hcxwd/p/9188878.html