av一区二区在线观看_亚洲男人的天堂网站_日韩亚洲视频_在线成人免费_欧美日韩精品免费观看视频_久草视

您的位置:首頁技術(shù)文章
文章詳情頁

vue倒計(jì)時(shí)刷新頁面不會(huì)從頭開始的解決方法

瀏覽:60日期:2023-02-04 08:52:04

開啟倒計(jì)時(shí),直接保存到vuex中,且存儲(chǔ)到本地持久化

// state.jsconst runTime = localStorage.getItem(’time’);paymentRunTime:runTime

// mutations.jsTimeReduction(state) { this.timerId = setInterval(() => { if (state.paymentRunTime === 0) { state.paymentRunTime = 60; return clearInterval(this.timerId) } state.paymentRunTime -= 1; localStorage.setItem(’time’,state.paymentRunTime) },1000); },

在需要用到的頁面鉤子函數(shù)調(diào)用方法, created(){ this.$store.commit(TimeReduction) }

知識(shí)點(diǎn)擴(kuò)展:

倒計(jì)時(shí)實(shí)例代碼:

<template> <div class='captcha-row'> <input placeholder='輸入驗(yàn)證碼' auto-focus /> <div v-if='showtime===null' @click='send'> 獲取驗(yàn)證碼 </div> <div v-else class='captcha-button'> {{showtime}} </div> </div></template>

<script>export default { data() { return { // 計(jì)時(shí)器,注意需要進(jìn)行銷毀 timeCounter: null, // null 則顯示按鈕 秒數(shù)則顯示讀秒 showtime: null } }, methods: { // 倒計(jì)時(shí)顯示處理 countDownText(s) { this.showtime = `${s}s后重新獲取` }, // 倒計(jì)時(shí) 60秒 不需要很精準(zhǔn) countDown(times) { const self = this; // 時(shí)間間隔 1秒 const interval = 1000; let count = 0; self.timeCounter = setTimeout(countDownStart, interval); function countDownStart() { if (self.timeCounter == null) { return false; } count++ self.countDownText(times - count + 1); if (count > times) { clearTimeout(self.timeCounter) self.showtime = null; } else { self.timeCounter = setTimeout(countDownStart, interval) } } }, send() { this.countDown(60); } },}</script>

以上就是vue倒計(jì)時(shí)刷新頁面不會(huì)從頭開始的解決方法的詳細(xì)內(nèi)容,更多關(guān)于vue倒計(jì)時(shí)刷新頁面不會(huì)從頭開始的資料請(qǐng)關(guān)注好吧啦網(wǎng)其它相關(guān)文章!

標(biāo)簽: Vue
相關(guān)文章:
主站蜘蛛池模板: 欧美日韩高清一区 | 国产精久久久久久 | 亚洲精品乱码久久久久久久久 | 成人国产精品久久 | 国产精品久久久久久久久久 | 日本一区二区三区免费观看 | 国产一区在线免费观看 | 国产成人在线免费 | 天天干天天操天天看 | 一本一道久久a久久精品蜜桃 | 久久一级免费视频 | h视频免费在线观看 | 免费永久av | 久久久久一区二区三区 | 日日爱夜夜操 | 亚洲日韩中文字幕 | 国产精品久久久久久久免费大片 | 91精品国产手机 | 成人无遮挡毛片免费看 | 欧美日韩第一页 | 国产成人精品免费视频大全最热 | 久久久av| 亚洲精品国产偷自在线观看 | 国产成人免费 | 九九热在线视频 | 精品国产欧美 | 国产电影一区二区在线观看 | 9色网站 | 日日日日操| 浴室洗澡偷拍一区二区 | 成人在线视频免费观看 | 免费看欧美一级片 | 亚洲小视频在线播放 | 狠狠做深爱婷婷综合一区 | 精品亚洲一区二区三区四区五区 | 国产91在线观看 | 久久精品a级毛片 | 一区二区成人 | 国产精彩视频在线观看 | 欧美黄色网 | 欧美在线视频一区二区 |