Vue驗證碼60秒倒計時功能簡單實例代碼
更新時間:2018年06月22日 16:11:34 作者:Goodbye_Youth
這篇文章主要介紹了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秒倒計時功能簡單實例代碼,希望對大家有所幫助,如果大家有任何疑問請給我留言,小編會及時回復大家的。在此也非常感謝大家對腳本之家網(wǎng)站的支持!
相關(guān)文章
Vue利用mockjs編寫假數(shù)據(jù)并應用的問題記錄
這篇文章主要介紹了Vue利用mockjs編寫假數(shù)據(jù)并應用,本文通過實例代碼給大家詳細講解,對Vue?mockjs數(shù)據(jù)相關(guān)知識感興趣的朋友跟隨小編一起看看吧2022-12-12
利用vue-router實現(xiàn)二級菜單內(nèi)容轉(zhuǎn)換
這篇文章主要介紹了如何利用vue-router實現(xiàn)二級菜單內(nèi)容轉(zhuǎn)換,具有一定的參考價值,感興趣的小伙伴們可以參考一下2016-11-11
vue+watermark-dom實現(xiàn)頁面水印效果(示例代碼)
watermark.js 是基于 DOM 對象實現(xiàn)的 BS 系統(tǒng)的水印,確保系統(tǒng)保密性,安全性,降低數(shù)據(jù)泄密風險,簡單輕量,支持多屬性配置,本文將通過 vue 結(jié)合 watermark-dom 庫,教大家實現(xiàn)簡單而有效的頁面水印效果,感興趣的朋友跟隨小編一起看看吧2024-07-07

