最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

利用momentJs做一個(gè)倒計(jì)時(shí)組件(實(shí)例代碼)

 更新時(shí)間:2021年12月17日 16:52:51   作者:小菜波  
這篇文章主要介紹了利用momentJs做一個(gè)倒計(jì)時(shí)組件,本文通過(guò)實(shí)例代碼給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下

今天抽空給大家介紹下vue和moment做的一個(gè)倒計(jì)時(shí),具體內(nèi)容如下所示:

展示樣式:

<template>
    <div class="table-right flex-a-center">
        <div class="time-text">
            <span class="timeTextSpan" v-for="item,index of h" >{{item}}</span>
            <span class="timeTextSpan1" >: </span>
            <span class="timeTextSpan" v-for="item,index of m" >{{item}}</span>
            <span class="timeTextSpan1" >: </span>
            <span class="timeTextSpan" v-for="item,index of s" >{{item}}</span>
        </div>
    </div>
</template>
<script>
import moment from 'moment'
export default {
  props: {
    endTime: { }, //接收得最后時(shí)間 2021-12-17 16:29:20
  },
  data() {
    //這里存放數(shù)據(jù)
    return {
      h:'00',
      m:'00',
      s:'00',
      timer:null
    };
  },
  watch: {
    endTime: {
      handler(e) {
        if (e) {
          let self = this
          clearInterval(this.timer)
          this.timer = setInterval(function(){self.init()},1000)
        }
      },
      deep: true,
      immediate: true
    }
  },
  mounted() {
    let self = this
    self.init()
    clearInterval(this.timer)
    this.timer = setInterval(function(){self.init()},1000)
  },
  //方法集合
  methods: {
    init(){
        let time =moment(this.endTime).diff(moment())
        if(time <= 0){
          clearInterval(this.timer)
          this.onOver()
          return
        }
        let t = time / 1000;
        let d = Math.floor(t / (24 * 3600));  //剩余天數(shù),如果需要可以自行補(bǔ)上
        let h = Math.floor((t - 24 * 3600 * d) / 3600) + d*24;  //不需要天數(shù),把天數(shù)轉(zhuǎn)換成小時(shí)
        let _h = Math.floor((t - 24 * 3600 * d) / 3600)  //保留天數(shù)后得小時(shí)
        let m = Math.floor((t - 24 * 3600 * d - _h * 3600) / 60);
        let s = Math.floor((t - 24 * 3600 * d - _h * 3600 - m * 60));
       
        this.h = String(h).length == 1? '0'+String(h):String(h)
        this.m = String(m).length == 1? '0'+String(m):String(m)
        this.s = String(s).length == 1? '0'+String(s):String(s)
    },
    onOver() {
      this.$emit('over') //倒計(jì)時(shí)結(jié)束得回調(diào)
    }
 
  },
  beforeDestroy(){
    this.timer = null
    clearInterval(this.timer)
  }
}
</script>
<style lang='less' scoped>
@import url("@/assets/css/supplier.less");
 

  .table-right {
    font-size: 12px;
    color: #757e8a;
    .timeTextSpan{
      display: inline-block;
      width: 14px;
      height: 22px;
      text-align: center;
      background: #F1F0F0;
      border-radius: 2px;
      margin-right: 2px;
      font-size: 16px;
      color: #ff8a2b;
      font-weight: bold;
    }
    .timeTextSpan1{
      display: inline-block;
      width: 14px;
      text-align: center;
      vertical-align: bottom;
      color:#202D40;
      font-size: 16px;
      font-weight: bold;
    }
   
    .time-text {
      margin-left: 10px;
    }
  }
</style>

到此這篇關(guān)于利用momentJs做一個(gè)倒計(jì)時(shí)組件的文章就介紹到這了,更多相關(guān)momentJs倒計(jì)時(shí)組件內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

最新評(píng)論

裕民县| 辰溪县| 沂南县| 卢龙县| 绥芬河市| 信阳市| 彭阳县| 平武县| 尉氏县| 陈巴尔虎旗| 丰顺县| 安阳县| 右玉县| 浪卡子县| 溆浦县| 磴口县| 墨竹工卡县| 桑植县| 睢宁县| 基隆市| 上林县| 濮阳市| 伊吾县| 弋阳县| 桦甸市| 康定县| 彩票| 吉隆县| 秦皇岛市| 永川市| 辽中县| 闽侯县| 渝中区| 晋中市| 汝城县| 兰州市| 古田县| 中阳县| 祁门县| 德庆县| 梧州市|