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/

  • 相关阅读:
    WINFrom Excal 数据导入数据库
    Asp.net MVC 中Ajax的使用 [分享]
    C#高级二
    C#高级一
    C#入门基础三四
    C#入门基础三
    C#入门基础二
    《Think in Java》(六)访问权限控制
    TCP/IP 详解笔记
    Win7使用之查端口,杀进程
  • 原文地址:https://www.cnblogs.com/mailyuan/p/11678986.html
Copyright © 2011-2022 走看看