Vue驗證碼60秒倒計時功能簡單實例代碼
template
<template> <div class='login'> <div class="loginHeader"> <input type="tel" class="loginBtn border-bottom" placeholder="請輸入手機號" /> <input type="tel" class="codeBtn" placeholder="請輸入驗證碼" /> <input type="button" class="getNumber" v-model="codeMsg" @click="getCode" :disabled="codeDisabled" /> </div> </div> </template>
script
<script> export default { data() { return { // 是否禁用按鈕 codeDisabled: false, // 倒計時秒數(shù) countdown: 60, // 按鈕上的文字 codeMsg: '獲取驗證碼', // 定時器 timer: null } }, methods: { // 獲取驗證碼 getCode() { // 驗證碼60秒倒計時 if (!this.timer) { this.timer = setInterval(() => { if (this.countdown > 0 && this.countdown <= 60) { this.countdown--; if (this.countdown !== 0) { this.codeMsg = "重新發(fā)送(" + this.countdown + ")"; } else { clearInterval(this.timer); this.codeMsg = "獲取驗證碼"; this.countdown = 60; this.timer = null; this.codeDisabled = false; } } }, 1000) } } } } </script>
css(scss寫法)
<style> .login{ width: 100%; height: 100%; background: #F9F9F9; .loginHeader{ padding: 0 10px; background: #fff; margin-top: 20px; overflow: hidden; .loginBtn{ width: 100%; height: 42px; border: none; background: #fff; color: #444; border-radius: 4px; outline: none; padding-left: 3px; font-size: 1.4rem; box-sizing: border-box; -webkit-appearance:none; } .border-bottom{ border-bottom: 1px solid #F3F3F3; } .codeBtn{ width: 63%; height: 42px; border: none; background: #fff; color: #444; border-radius: 4px; float: left; outline: none; padding-left: 3px; font-size: 1.4rem; box-sizing: border-box; -webkit-appearance:none; } .getNumber{ width: 35%; height: 36px; float: right; margin-top: 3px; border: 1px solid #09BB07; color: #09BB07; background: #fff; border-radius: 4px; outline: none; -webkit-appearance:none; } } } </style>
總結(jié)
以上所述是小編給大家介紹的Vue驗證碼60秒倒計時功能簡單實例代碼,希望對大家有所幫助,如果大家有任何疑問請給我留言,小編會及時回復(fù)大家的。在此也非常感謝大家對腳本之家網(wǎng)站的支持!
相關(guān)文章
Vue?中的?computed?和?watch?的區(qū)別詳解
這篇文章主要介紹了Vue中的computed和watch的區(qū)別詳解,文章圍繞主題展開詳細的內(nèi)容介紹,具有一定的參考價值,需要的小伙伴可以參考一下2022-09-09vue點擊右鍵出現(xiàn)自定義操作菜單實現(xiàn)代碼
這篇文章主要給大家介紹了關(guān)于vue點擊右鍵出現(xiàn)自定義操作菜單實現(xiàn)的相關(guān)資料,在網(wǎng)頁中我們也希望可以像桌面軟件一樣,點擊右鍵后出現(xiàn)操作菜單,對選中的數(shù)據(jù)項進行相應(yīng)的操作,需要的朋友可以參考下2023-08-08vue2和elementUI?實現(xiàn)落日余暉登錄頁和滑塊校驗功能
這篇文章主要介紹了vue2和elementUI打造落日余暉登錄頁和滑塊校驗,本文通過實例代碼給大家介紹的非常詳細,需要的朋友可以參考下2023-06-06vue 通過 Prop 向子組件傳遞數(shù)據(jù)的實現(xiàn)方法
這篇文章主要介紹了vue 通過 Prop 向子組件傳遞數(shù)據(jù)的實現(xiàn)方法,文中通過示例代碼介紹的非常詳細,對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2020-10-10vue項目如何讓局域網(wǎng)ip訪問配置設(shè)置
這篇文章主要介紹了vue項目如何讓局域網(wǎng)ip訪問配置設(shè)置,具有很好的參考價值,希望對大家有所幫助。2022-09-09vue實現(xiàn)微信分享朋友圈,發(fā)送朋友的示例講解
下面小編就為大家分享一篇vue實現(xiàn)微信分享朋友圈,發(fā)送朋友的示例講解,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2018-02-02Element框架el-tab點擊標(biāo)簽頁時再渲染問題的解決
本文主要介紹了Element框架el-tab點擊標(biāo)簽頁時再渲染問題的解決,文中通過示例代碼介紹的非常詳細,對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2022-04-04