其他分享
首页 > 其他分享> > js(react)60s 验证码倒计时方法

js(react)60s 验证码倒计时方法

作者:互联网

60s 验证码倒计时方法

    //60s倒计时
    const handleCountDown = (seconds = 60) => {
        // let second = 60;
        let second = seconds;
        const countDown = ()=> {
            // timer && clearTimeout(timer); //清除计时器
            if( second > 0){
                // let second =
                // countDownSecond--;
                // let a  = countDownSecond - 1;
                second--;
                setCountDownSecond( second );
            }
            if( second === 0 ){
                /*
                    _this.countDown = 60;//恢复60s设定
                    _this.isVerify = false;//不显示60s计时器
                    clearTimeout(count60Timeout)//清除计时器
                    return //结束方法的调用
                */
                second = 60;
                setCountDownSecond( second );
                // clearTimeout( timer ); //清除计时器
                return;
            }
            // let timer = setTimeout( countDown,1000 );
            setTimeout( countDown,1000 );
        };
        setTimeout( countDown,1000 );
    };

 

调用  handleCountDown(60) 此方法即可实现60s 倒计时 

 

标签:60,60s,timer,js,react,second,let,countDown
来源: https://www.cnblogs.com/taohuaya/p/13070342.html