午夜剧场伦理_日本一道高清_国产又黄又硬_91黄色网战_女同久久另类69精品国产_妹妹的朋友在线

您的位置:首頁技術文章
文章詳情頁

Vue 封裝防刷新考試倒計時組件的實現

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

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

Vue 封裝防刷新考試倒計時組件的實現

<!-- 考試倒計時組件 --><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>

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

標簽: Vue
相關文章:
主站蜘蛛池模板: 激情婷婷丁香 | 天天射日 | 在线视频中文字幕 | 国产成人精品久久二区二区91 | 91久久精品一区二区三区 | 天天视频黄色 | 日韩成人区 | 亚洲一区黄色 | 在线视频观看一区 | 欧美性aaa | 在线免费观看黄色av | 最近中文字幕在线中文高清版 | 欧美日韩在线免费视频 | 日本激情久久 | 影音先锋男人网 | 欧美亚洲在线视频 | 99re这里只有精品6 | 天天操天天干天天插 | 日韩精品一区二区三区在线 | 四虎免费视频 | 一二三区视频 | 老熟妇毛片 | 亚洲欧美一区二区三区情侣bbw | 国产精品二区三区 | 欧美一级一区二区三区 | 成人网在线观看 | 男女碰碰碰 | 日本黄色小视频 | 久久九九免费视频 | 一级黄色淫片 | 成人午夜免费影院 | 国产黄色免费看 | www黄色网址 | 日韩三级在线观看视频 | www.av天天| 欧日韩不卡视频 | 在线一二三区 | 麻豆一区二区 | 亚洲国产精品二区 | 免费在线中文字幕 | 国产精选一区 |