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

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

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

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

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

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

<!-- 考試倒計(jì)時(shí)組件 --><template> <div class='time'> <p>00:{{timerCount2}}:{{timerCount1}}</p> <button @click='reset'>重新計(jì)時(shí)</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; }, // 重新計(jì)時(shí) 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); }, // 倒計(jì)時(shí) 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); //存儲(chǔ)秒 } if (startTime2) { this.timeMinutes = startTime2; } else { this.timeMinutes = this.minutes; localStorage.setItem('startTime2', this.minutes); //存儲(chǔ)分 } 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('考試時(shí)間到'); } 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() { // 退出后清除計(jì)時(shí)器 if (this.timer) { clearInterval(this.timer); } }};</script><style scoped>.time { color: #f72a3a; font-weight: bold; font-size: 26px;}</style>

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

標(biāo)簽: Vue
相關(guān)文章:
主站蜘蛛池模板: 精品在线视频播放 | 久久久久国产一区二区三区四区 | 亚洲国产视频一区二区 | 亚洲第一视频网站 | 国产精品99久久久久久动医院 | 国产一级视频在线播放 | 欧美一区二区成人 | 欧美日韩在线视频一区二区 | 欧美精品久久 | 日韩一二区 | 欧美一区二区三区 | 日本一区精品 | 国产精品不卡一区 | 久久久久久久综合 | 在线播放国产一区二区三区 | 国产一级在线 | 亚洲欧美日韩高清 | 亚洲成人免费观看 | 国产精品免费一区二区三区四区 | 天天躁日日躁性色aⅴ电影 免费在线观看成年人视频 国产欧美精品 | 一级毛片视频在线 | 亚洲精品一区二区三区蜜桃久 | 久久久久国产一区二区 | 欧美男人天堂 | 亚洲一区二区三区国产 | 天堂男人av | 91在线精品视频 | 一区二区三区四区国产 | 天天干天天爱天天爽 | 日韩国产精品一区二区三区 | 青青青伊人 | 男人天堂视频在线观看 | 国产精品日韩欧美一区二区三区 | 久久午夜精品 | 嫩草影院网址 | 亚洲视频在线一区 | 国产精品久久 | 狠狠做六月爱婷婷综合aⅴ 国产精品视频网 | 日韩资源| 国产欧美精品一区二区色综合朱莉 | 国产97在线 | 日韩 |