zoukankan      html  css  js  c++  java
  • vue项目增加倒计时功能

    需要使用vue-countdown来实现

    1. 下载&引入

    2. 使用

    HTML部分:

    <div id="app">
      <countdown :time="time" :interval="100" tag="p">
        <template slot-scope="props">New Year Countdown:{{ props.days }} days, {{ props.hours }} hours, {{ props.minutes }} minutes, {{ props.seconds }}.{{ Math.floor(props.milliseconds / 100) }} seconds.</template>
      </countdown>
    
      <countdown ="time" tag="p">
        <template slot-scope="props">Christmas Time Remaining: {{ props.totalDays }} days / {{ props.totalHours }} hours / {{ props.totalMinutes }} minutes / {{ props.totalSeconds }} seconds / {{ props.totalMilliseconds }} milliseconds.</template>
      </countdown>
    
      <button type="button" class="btn btn-secondary" :disabled="counting" @click="startCountdown">
        <countdown v-if="counting" :time="60000" @end="handleCountdownEnd">
          <template slot-scope="props">Fetch again {{ props.totalSeconds }} seconds later</template>
        </countdown>
        <span v-else>Fetch Verification Code</span>
      </button>
    </div>

    js部分:

    window.onload = function () {
        Vue.component(VueCountdown.name, VueCountdown);
    
        new Vue({
          el: '#app',
          data: function () {
            var now = new Date();
            var newYear = new Date(now.getFullYear() + 1, 0, 1);
    
            return {
              counting: false,
              time: newYear - now,
            };
          },
          methods: {
            startCountdown: function () {
              this.counting = true;
            },
            handleCountdownEnd: function () {
              this.counting = false;
            },
          }
        });
      };

    总结: 是需要将开始的时间戳绑定给time即可

    参考:

    https://github.com/fengyuanchen/vue-countdown#table-of-contents

    https://fengyuanchen.github.io/vue-countdown/

  • 相关阅读:
    【模板】后缀自动机
    【模板】矩阵求逆
    【hdu5517】Triple
    【模板】多标记 LCT
    【洛谷P4172】水管局长
    【模板】LCT
    【CF786B】Legacy
    jacoco学习
    python + redis
    Python Gitlab Api 使用方法
  • 原文地址:https://www.cnblogs.com/mailyuan/p/11678986.html
Copyright © 2011-2022 走看看