Vue驗(yàn)證碼60秒倒計(jì)時(shí)功能簡(jiǎn)單實(shí)例代碼
template
<template> <div class='login'> <div class="loginHeader"> <input type="tel" class="loginBtn border-bottom" placeholder="請(qǐng)輸入手機(jī)號(hào)" /> <input type="tel" class="codeBtn" placeholder="請(qǐng)輸入驗(yàn)證碼" /> <input type="button" class="getNumber" v-model="codeMsg" @click="getCode" :disabled="codeDisabled" /> </div> </div> </template>
script
<script>
export default {
data() {
return {
// 是否禁用按鈕
codeDisabled: false,
// 倒計(jì)時(shí)秒數(shù)
countdown: 60,
// 按鈕上的文字
codeMsg: '獲取驗(yàn)證碼',
// 定時(shí)器
timer: null
}
},
methods: {
// 獲取驗(yàn)證碼
getCode() {
// 驗(yàn)證碼60秒倒計(jì)時(shí)
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 = "獲取驗(yàn)證碼";
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驗(yàn)證碼60秒倒計(jì)時(shí)功能簡(jiǎn)單實(shí)例代碼,希望對(duì)大家有所幫助,如果大家有任何疑問(wèn)請(qǐng)給我留言,小編會(huì)及時(shí)回復(fù)大家的。在此也非常感謝大家對(duì)腳本之家網(wǎng)站的支持!
- 簡(jiǎn)單實(shí)現(xiàn)vue驗(yàn)證碼60秒倒計(jì)時(shí)功能
- Vue通過(guò)for循環(huán)隨機(jī)生成不同的顏色或隨機(jī)數(shù)的實(shí)例
- 基于vue實(shí)現(xiàn)圖片驗(yàn)證碼倒計(jì)時(shí)60s功能
- Vue實(shí)現(xiàn)手機(jī)號(hào)、驗(yàn)證碼登錄(60s禁用倒計(jì)時(shí))
- vue組件封裝實(shí)現(xiàn)抽獎(jiǎng)隨機(jī)數(shù)
- vue中如何使用唯一標(biāo)識(shí)uuid(uuid.v1()-時(shí)間戳、uuid.v4()-隨機(jī)數(shù))
- Vue3+Hooks實(shí)現(xiàn)4位隨機(jī)數(shù)和60秒倒計(jì)時(shí)的示例代碼
相關(guān)文章
vue 的keep-alive緩存功能的實(shí)現(xiàn)
本篇文章主要介紹了vue 的keep-alive緩存功能的實(shí)現(xiàn),小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧2018-03-03
Vue利用mockjs編寫假數(shù)據(jù)并應(yīng)用的問(wèn)題記錄
這篇文章主要介紹了Vue利用mockjs編寫假數(shù)據(jù)并應(yīng)用,本文通過(guò)實(shí)例代碼給大家詳細(xì)講解,對(duì)Vue?mockjs數(shù)據(jù)相關(guān)知識(shí)感興趣的朋友跟隨小編一起看看吧2022-12-12
vue-cli 3.0 引入mint-ui報(bào)錯(cuò)問(wèn)題及解決
這篇文章主要介紹了vue-cli 3.0 引入mint-ui報(bào)錯(cuò)問(wèn)題及解決方案,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2022-05-05
利用vue-router實(shí)現(xiàn)二級(jí)菜單內(nèi)容轉(zhuǎn)換
這篇文章主要介紹了如何利用vue-router實(shí)現(xiàn)二級(jí)菜單內(nèi)容轉(zhuǎn)換,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2016-11-11
vue+watermark-dom實(shí)現(xiàn)頁(yè)面水印效果(示例代碼)
watermark.js 是基于 DOM 對(duì)象實(shí)現(xiàn)的 BS 系統(tǒng)的水印,確保系統(tǒng)保密性,安全性,降低數(shù)據(jù)泄密風(fēng)險(xiǎn),簡(jiǎn)單輕量,支持多屬性配置,本文將通過(guò) vue 結(jié)合 watermark-dom 庫(kù),教大家實(shí)現(xiàn)簡(jiǎn)單而有效的頁(yè)面水印效果,感興趣的朋友跟隨小編一起看看吧2024-07-07

