2020-03-26 倒計(jì)時(shí)處理

一:<div?class="flex?align-items-center">

??????????????<van-button

????????????????plain

????????????????:loading="isLoadingYzm"

????????????????:class="{'border-0':codeSrc}"

????????????????color="#80CA63"

????????????????style="background:#FFFFFF;margin-top:5%"

????????????????@click="getYzm5"

??????????????>

????????????????<span?v-if="showtime===null"?>獲取驗(yàn)證碼</span>

????????????????<span?v-else>{{showtime}}</span>

??????????????</van-button>

????????????</div>




二:data()定義

??//?計(jì)時(shí)器,注意需要進(jìn)行銷毀

??????timeCounter:?null,

??????//?null?則顯示按鈕?秒數(shù)則顯示讀秒

??????showtime:?null,


三:methods里設(shè)置倒計(jì)時(shí)

?// 1,倒計(jì)時(shí)顯示處理

?countDownText(s)?{

??this.showtime?=?`${s}s后重新獲取`

?},

//2, 倒計(jì)時(shí)?60秒?不需要很精準(zhǔn)

?countDown(times)?{

??const?self?=?this;

??//?時(shí)間間隔?1秒

??const?interval?=?1000;

??let?count?=?0;

??self.timeCounter?=?setTimeout(countDownStart,?interval);

??function?countDownStart()?{

??if?(self.timeCounter?==?null)?{

???return?false;

??}

??count++

??self.countDownText(times?-?count?+?1);

??if?(count?>?times)?{

???clearTimeout(self.timeCounter)

???self.showtime?=?null;

??}?else?{

???self.timeCounter?=?setTimeout(countDownStart,?interval)

??}

??}

?},

//3,注冊(cè)根據(jù)手機(jī)號(hào)獲取驗(yàn)證碼

????getYzm()?{

??????//?根據(jù)短信注冊(cè)賬號(hào)

??????if?(this.phone?==?"")?{

????????window.vant.Toast("請(qǐng)輸入手機(jī)號(hào)碼");

????????return;

??????}?else?{

????????if?(!/^1[3456789]\d{9}$/.test(this.phone))?{

??????????window.vant.Toast("手機(jī)號(hào)碼有誤,請(qǐng)重填");

??????????return?false;?

????????}

??????}

??????this.API.sendMsg({

????????phone:?this.phone

??????})

????????.then(res?=>?{

??????????if?(res.code?==?200)?{

????????????this.countDown(60);

????????????window.vant.Toast(res.msg);

??????????}?else?{

????????????//?this.isLoadingYzm?=?false;

????????????window.vant.Toast(res.msg);

??????????}

????????})

????????.catch(err?=>?{

??????????console.log(err);

????????});

????},

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容