vue發(fā)送驗證碼計時器防止刷新實(shí)現(xiàn)詳解
更新時間:2023年03月09日 10:59:28 作者:藍(lán)色海島
這篇文章主要為大家介紹了vue發(fā)送驗證碼計時器防止刷新實(shí)現(xiàn)詳解,<BR>有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪
基本實(shí)現(xiàn)效果
按鈕:
<t-button @click="handleSend" :disabled="disable">{{text}}</t-button>
data:
text: '發(fā)送驗證碼',
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ā)送驗證碼計時器防止刷新實(shí)現(xiàn)詳解的詳細(xì)內(nèi)容,更多關(guān)于vue發(fā)送驗證碼計時器防止刷新的資料請關(guān)注腳本之家其它相關(guān)文章!
相關(guān)文章
vite中的glob-import批量導(dǎo)入的實(shí)現(xiàn)
本文主要介紹了vite中的glob-import批量導(dǎo)入的實(shí)現(xiàn),文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2023-07-07
使用Vant完成DatetimePicker 日期的選擇器操作
這篇文章主要介紹了使用Vant完成DatetimePicker 日期的選擇器操作,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2020-11-11
Vue-resource攔截器判斷token失效跳轉(zhuǎn)的實(shí)例
下面小編就為大家?guī)硪黄猇ue-resource攔截器判斷token失效跳轉(zhuǎn)的實(shí)例。小編覺得挺不錯的,現(xiàn)在就分享給大家,也給大家做個參考。一起跟隨小編過來看看吧2017-10-10

