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 倒計時 

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM