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