vue發(fā)送驗(yàn)證碼計(jì)時(shí)器防止刷新實(shí)現(xiàn)詳解
基本實(shí)現(xiàn)效果
按鈕:
<t-button @click="handleSend" :disabled="disable">{{text}}</t-button>
data:
text: '發(fā)送驗(yàn)證碼',
time: 10,
timer: null,
disable: false
點(diǎn)擊發(fā)送:
handleSend() {
this.disable = true
this.text = this.time + 's后重新發(fā)送'
this.timer = setInterval(() => {
if (this.time > 0) {
this.time--
this.text = this.time + 's后重新發(fā)送'
} else {
clearInterval(this.timer)
this.time = 10
this.disable = false
this.text = '重新發(fā)送'
}
}, 1000)
}
防止刷新
handleSend() {
this.disable = true
this.text = this.time + 's后重新發(fā)送'
this.timer = setInterval(() => {
if (this.time > 0) {
this.time--
this.text = this.time + 's后重新發(fā)送'
localStorage.setItem('time', this.time) // 注意這行
} else {
clearInterval(this.timer)
this.time = 10
this.disable = false
this.text = '重新發(fā)送'
}
}, 1000)
}
created() {
const time = localStorage.getItem('time')
if (time && time > 0) {
this.text = time + 's后重新發(fā)送'
this.time = time
this.handleSend()
}
}以上就是vue發(fā)送驗(yàn)證碼計(jì)時(shí)器防止刷新實(shí)現(xiàn)詳解的詳細(xì)內(nèi)容,更多關(guān)于vue發(fā)送驗(yàn)證碼計(jì)時(shí)器防止刷新的資料請(qǐng)關(guān)注腳本之家其它相關(guān)文章!
相關(guān)文章
vite中的glob-import批量導(dǎo)入的實(shí)現(xiàn)
本文主要介紹了vite中的glob-import批量導(dǎo)入的實(shí)現(xiàn),文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2023-07-07
使用Vant完成DatetimePicker 日期的選擇器操作
這篇文章主要介紹了使用Vant完成DatetimePicker 日期的選擇器操作,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧2020-11-11
vite構(gòu)建vue3項(xiàng)目的全過(guò)程記錄
vite是VUE3創(chuàng)建項(xiàng)目的工具,項(xiàng)目大了之后,性能明顯優(yōu)于webpack,下面這篇文章主要給大家介紹了關(guān)于vite構(gòu)建vue3項(xiàng)目的相關(guān)資料,需要的朋友可以參考下2023-01-01
Vue-resource攔截器判斷token失效跳轉(zhuǎn)的實(shí)例
下面小編就為大家?guī)?lái)一篇Vue-resource攔截器判斷token失效跳轉(zhuǎn)的實(shí)例。小編覺(jué)得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧2017-10-10
antd vue v-decorator的取值與賦值問(wèn)題
這篇文章主要介紹了antd vue v-decorator的取值與賦值問(wèn)題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2023-04-04

