vue實(shí)現(xiàn)驗(yàn)證碼倒計(jì)時(shí)按鈕
本文實(shí)例為大家分享了vue實(shí)現(xiàn)驗(yàn)證碼倒計(jì)時(shí)按鈕的具體代碼,供大家參考,具體內(nèi)容如下
1、點(diǎn)擊“發(fā)送驗(yàn)證碼”按鈕后進(jìn)行邏輯判斷:
▶️ 如果郵箱已輸入且格式正確:按鈕變?yōu)?strong>“已發(fā)送” ,此時(shí)為不可點(diǎn)擊狀態(tài) 并開始120s倒計(jì)時(shí);
▶️ 如果郵箱未輸入或格式不正確:顯示錯(cuò)誤的提示信息。
2、120s倒計(jì)時(shí)結(jié)束后按鈕變?yōu)?span style="color: #800000">“重新發(fā)送驗(yàn)證碼” 。
html:
<div v-bind:class="{ 'text_email': isActive, 'text_tip': isTip }">{{tip}}</div> //出錯(cuò)提示 <div class="input"> <i class="ret_icon-email"></i> <input type="text" v-model="email" v-bind:class="{ 'input_email0' : hasError }" v-on:click="cancelError" :placeholder="輸入郵箱地址" id="inputEmail" /> <br /> <input type="text" placeholder="輸入驗(yàn)證碼" class="input_number" /> <button class="btn_number" v-bind:class="{gray:wait_timer>0}" @click="getCode()"> <span class="num_green" v-show="showNum" v-bind:class="{num:wait_timer>0}" >{{this.wait_timer + "s "}}</span> <span class="span_number" v-bind:class="{gray_span:wait_timer>0}" >{{ getCodeText() }}</span> </button> <br /> </div>
js:
data() { return { tip: "用Email找回密碼", isTip: false, isActive: true, showNum: false, wait_timer: false, hasError: false, email: "" } }, methods: { cancelError: function(event) { this.hasError = false; this.isActive = true; this.isTip = false; this.tip = "用Email找回密碼"; }, getCode: function() { if (this.wait_timer > 0) { return false; } if (!this.email) { this.hasError = true; this.isActive = false; this.isTip = true; this.tip = "Email不能為空"; return false; } if ( !/^([a-zA-Z0-9]+[_|\_|\.]?)*[a-zA-Z0-9]+@([a-zA-Z0-9]+[_|\_|\.]?)*[a-zA-Z0-9]+\.[a-zA-Z]{2,3}$/.test( this.email ) ) { this.hasError = true; this.isActive = false; this.isTip = true; this.tip = "Email地址無效"; return false; } this.showNum = true; this.wait_timer = 120; var that = this; var timer_interval = setInterval(function() { if (that.wait_timer > 0) { that.wait_timer--; } else { clearInterval(timer_interval); } }, 1000); //在這里調(diào)取你獲取驗(yàn)證碼的ajax }, getCodeText: function() { if (this.wait_timer > 0) { return "已發(fā)送"; } if (this.wait_timer === 0) { this.showNum = false; return "重新發(fā)送驗(yàn)證碼!"; } if (this.wait_timer === false) { return "發(fā)送驗(yàn)證碼!"; } }, }
css:
.ret_icon-email { background: url(../../assets/pics/email.svg) no-repeat; //圖片為本地圖片 width: 20px; height: 20px; position: absolute; top: 12px; left: 16px; } .input_email0 { border: 1px solid rgba(239, 83, 80, 1); } .input_number { width: 112px; height: 44px; text-indent: 16px; margin-right: 12px; } .btn_number { width: 154px; height: 44px; border-radius: 4px; box-sizing: border-box; border: 1px solid rgba(76, 175, 80, 1); line-height: 16px; outline: none; } .span_number { color: rgba(76, 175, 80, 1); } .btn_number.gray { background: rgba(242, 244, 245, 1); border: 1px solid rgba(0, 0, 0, 0.05); } .span_number.gray_span { color: #9a9c9a; } .num_green.num { color: rgba(76, 175, 80, 1); }
效果圖:
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
- Vue3?實(shí)現(xiàn)驗(yàn)證碼倒計(jì)時(shí)功能
- vue實(shí)現(xiàn)列表倒計(jì)時(shí)
- Vue3?實(shí)現(xiàn)驗(yàn)證碼倒計(jì)時(shí)功能(刷新保持狀態(tài))
- vue實(shí)現(xiàn)點(diǎn)擊按鈕倒計(jì)時(shí)
- Vue實(shí)現(xiàn)倒計(jì)時(shí)小功能
- vue實(shí)現(xiàn)時(shí)間倒計(jì)時(shí)功能
- vue實(shí)現(xiàn)同時(shí)設(shè)置多個(gè)倒計(jì)時(shí)
- Vue倒計(jì)時(shí)3秒后返回首頁(yè)Demo(推薦)
相關(guān)文章
Vue3響應(yīng)式對(duì)象Reactive和Ref的用法解讀
這篇文章主要介紹了Vue3響應(yīng)式對(duì)象Reactive和Ref的用法,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2022-09-09vue使用自定義指令實(shí)現(xiàn)按鈕權(quán)限展示功能
這篇文章主要介紹了vue中使用自定義指令實(shí)現(xiàn)按鈕權(quán)限展示功能,本文結(jié)合實(shí)例代碼給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2022-04-04mui-player自定義底部導(dǎo)航在vue項(xiàng)目中顯示不出來的解決
這篇文章主要介紹了mui-player自定義底部導(dǎo)航在vue項(xiàng)目中顯示不出來的解決方案,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2022-12-12vue?實(shí)現(xiàn)動(dòng)態(tài)設(shè)置元素的高度
這篇文章主要介紹了在vue中實(shí)現(xiàn)動(dòng)態(tài)設(shè)置元素的高度,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2022-08-08Vue結(jié)合ElementUI實(shí)現(xiàn)數(shù)據(jù)請(qǐng)求和頁(yè)面跳轉(zhuǎn)功能(最新推薦)
我們?cè)赑roflie.vue實(shí)例中,有beforeRouteEnter、beforeRouteLeave兩個(gè)函數(shù)分別是進(jìn)入路由之前和離開路由之后,我們可以在這兩個(gè)函數(shù)之內(nèi)進(jìn)行數(shù)據(jù)的請(qǐng)求,下面給大家分享Vue結(jié)合ElementUI實(shí)現(xiàn)數(shù)據(jù)請(qǐng)求和頁(yè)面跳轉(zhuǎn)功能,感興趣的朋友一起看看吧2024-05-05Vue腳手架學(xué)習(xí)之項(xiàng)目創(chuàng)建方式
這篇文章主要給大家介紹了關(guān)于Vue腳手架學(xué)習(xí)之項(xiàng)目創(chuàng)建方式的相關(guān)資料,文中通過介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2021-03-03