欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

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

 更新時(shí)間:2020年06月05日 09:22:43   作者:Vam的金豆之路  
這篇文章主要介紹了Vue 封裝防刷新考試倒計(jì)時(shí)組件的實(shí)現(xiàn),文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧

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

<!-- 考試倒計(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); //存儲秒
   }
   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("考試時(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)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

  • vue2.0 和 animate.css的結(jié)合使用

    vue2.0 和 animate.css的結(jié)合使用

    animate.css是一款前端動畫庫,相似的有velocity-animate。這篇文章給大家介紹vue2.0 和 animate.css的結(jié)合使用,需要的朋友參考下吧
    2017-12-12
  • Vue動態(tài)加載圖片在跨域時(shí)無法顯示的問題及解決方法

    Vue動態(tài)加載圖片在跨域時(shí)無法顯示的問題及解決方法

    這篇文章主要介紹了解決VUE動態(tài)加載圖片在跨域時(shí)無法顯示的問題,本文通過實(shí)例代碼給大家介紹的非常詳細(xì),對大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
    2020-03-03
  • vue自定義密碼輸入框解決瀏覽器自動填充密碼的問題(最新方法)

    vue自定義密碼輸入框解決瀏覽器自動填充密碼的問題(最新方法)

    這篇文章主要介紹了vue自定義密碼輸入框解決瀏覽器自動填充密碼的問題,通過將密碼輸入框的type設(shè)置為text,修改樣式上的顯示,來實(shí)現(xiàn)既可以讓瀏覽器不自動填充密碼,又可以隱藏密碼的效果,需要的朋友可以參考下
    2023-04-04
  • vue2使用?element表格展開功能渲染子表格的方式

    vue2使用?element表格展開功能渲染子表格的方式

    這篇文章主要介紹了vue2使用?element表格展開功能渲染子表格的方式,本文通過實(shí)例代碼給大家介紹的非常詳細(xì),對大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友參考下吧
    2024-01-01
  • vue項(xiàng)目前端微信JSAPI與外部H5支付相關(guān)實(shí)現(xiàn)過程及常見問題

    vue項(xiàng)目前端微信JSAPI與外部H5支付相關(guān)實(shí)現(xiàn)過程及常見問題

    這篇文章主要介紹了vue項(xiàng)目前端微信JSAPI與外部H5支付相關(guān)實(shí)現(xiàn)過程及常見問題,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2020-04-04
  • Vue3 封裝回到頂部組件的實(shí)現(xiàn)示例

    Vue3 封裝回到頂部組件的實(shí)現(xiàn)示例

    回到頂部在很多網(wǎng)頁中都可以見到,本文主要介紹了Vue3 封裝回到頂部組件的實(shí)現(xiàn)示例,文中根據(jù)實(shí)例編碼詳細(xì)介紹的十分詳盡,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2022-03-03
  • vue使用localStorage保存登錄信息 適用于移動端、PC端

    vue使用localStorage保存登錄信息 適用于移動端、PC端

    這篇文章主要為大家詳細(xì)介紹了vue使用localStorage保存登錄信息 適用于移動端、PC端,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2019-05-05
  • vue封裝tree組件實(shí)現(xiàn)搜索功能

    vue封裝tree組件實(shí)現(xiàn)搜索功能

    本文主要介紹了vue封裝tree組件實(shí)現(xiàn)搜索功能,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2023-05-05
  • vuex實(shí)現(xiàn)購物車的增加減少移除

    vuex實(shí)現(xiàn)購物車的增加減少移除

    這篇文章主要為大家詳細(xì)介紹了vuex實(shí)現(xiàn)購物車的增加減少移除,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2020-06-06
  • 羊了個(gè)羊通關(guān)腳本Vue?node實(shí)現(xiàn)版本

    羊了個(gè)羊通關(guān)腳本Vue?node實(shí)現(xiàn)版本

    這篇文章主要為大家介紹了羊了個(gè)羊通關(guān)腳本Vue?node實(shí)現(xiàn)版本,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪
    2022-09-09

最新評論