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

2021-02-08 19:18

阅读:353

标签:handle   verify   out   div   style   react   clear   计时   second   

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 倒计时 

 

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

标签:handle   verify   out   div   style   react   clear   计时   second   

原文地址:https://www.cnblogs.com/taohuaya/p/13070342.html


评论


亲,登录后才可以留言!