国产成人精品久久免费动漫-国产成人精品天堂-国产成人精品区在线观看-国产成人精品日本-a级毛片无码免费真人-a级毛片毛片免费观看久潮喷

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

Vue 封裝防刷新考試倒計時組件的實現(xiàn)

瀏覽:20日期:2023-01-15 17:19:02

本文詳細(xì)的介紹了防刷新考試倒計時組件 ,分享給大家,也給自己留個筆記,感興趣的可以了解下

Vue 封裝防刷新考試倒計時組件的實現(xiàn)

<!-- 考試倒計時組件 --><template> <div class='time'> <p>00:{{timerCount2}}:{{timerCount1}}</p> <button @click='reset'>重新計時</button> </div></template><script>export default { name: 'Time', data() { return { timeSeconds: 0, timeMinutes: 0, seconds: 59, // 秒 minutes: 1, // 分 timer: null }; }, methods: { num(n) { return n < 10 ? '0' + n : '' + n; }, // 重新計時 reset() { sessionStorage.removeItem('answered'); window.location.reload(); localStorage.removeItem('startTime1'); localStorage.removeItem('startTime2'); clearInterval(this.timer); }, // 清除 clear() { localStorage.removeItem('startTime1'); localStorage.removeItem('startTime2'); sessionStorage.setItem('answered', 1); clearInterval(this.timer); }, // 倒計時 timing() { let [startTime1, startTime2] = [ localStorage.getItem('startTime1'), localStorage.getItem('startTime2') ]; let nowTime = new Date().getTime(); if (startTime1) { let surplus = this.seconds - parseInt((nowTime - startTime1) / 1000); this.timeSeconds = surplus <= 0 ? 0 : surplus; } else { this.timeSeconds = this.seconds; localStorage.setItem('startTime1', nowTime); //存儲秒 } if (startTime2) { this.timeMinutes = startTime2; } else { this.timeMinutes = this.minutes; localStorage.setItem('startTime2', this.minutes); //存儲分 } this.timer = setInterval(() => { if ( this.timeSeconds == 0 && this.timeMinutes != 0 && this.timeMinutes > 0 ) { let nowTime = new Date().getTime(); this.timeSeconds = this.seconds; localStorage.setItem('startTime1', nowTime); this.timeMinutes--; localStorage.setItem('startTime2', this.timeMinutes); } else if (this.timeMinutes == 0 && this.timeSeconds == 0) { this.timeSeconds = 0; this.clear(); alert('考試時間到'); } else { this.timeSeconds--; } }, 1000); } }, mounted() { if (sessionStorage.getItem('answered') != 1) { this.timing(); } }, computed: { timerCount1() { return this.timeSeconds < 10 ? '0' + this.timeSeconds : '' + this.timeSeconds; }, timerCount2() { return this.timeMinutes < 10 ? '0' + this.timeMinutes : '' + this.timeMinutes; } }, destroyed() { // 退出后清除計時器 if (this.timer) { clearInterval(this.timer); } }};</script><style scoped>.time { color: #f72a3a; font-weight: bold; font-size: 26px;}</style>

到此這篇關(guān)于Vue 封裝防刷新考試倒計時組件的實現(xiàn)的文章就介紹到這了,更多相關(guān)Vue 防刷新考試倒計時組件內(nèi)容請搜索好吧啦網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持好吧啦網(wǎng)!

標(biāo)簽: Vue
相關(guān)文章:
主站蜘蛛池模板: 玖玖这里只有精品 | 欧美丰满大乳大屁股毛片 | 在线精品视频在线观看高清 | 99精品高清不卡在线观看 | 色综合精品久久久久久久 | 白浆在线视频 | 久久网站在线观看 | 天天看片欧美 | 久草在线观看福利 | 国产成人18黄网站免费网站 | 日韩一区二区不卡中文字幕 | 久久免费99精品久久久久久 | 精品三级在线观看 | 亚洲日韩中文字幕天堂不卡 | 亚洲三级理论 | 国产网站在线看 | 精品国产91在线网 | 9191精品国产观看 | 欧美成人性生活视频 | 伊人久久精品午夜 | 爽爽窝窝午夜精品一区二区 | 成人一级免费视频 | 亚洲一区在线观看视频 | 成人午夜性视频欧美成人 | 日韩欧美高清在线观看 | www.日本三级| 三级c欧美做人爱视频 | 国产成人18黄网站在线观看网站 | 欧洲97色综合成人网 | 纯欧美一级毛片免费 | 综合刺激网 | 国产超薄肉色丝袜足j | 萌白酱国产一区 | 成人在线免费小视频 | 欧美一级大片在线观看 | 性盈盈影院在线观看 | 亚洲图片 自拍 | a级片免费在线播放 | 亚洲日本一区二区三区高清在线 | 欧美高清在线视频一区二区 | 久久中文亚洲国产 |