node.js+vue的倒计时

**倒计时
xx时xx分xx秒 **

src/App.vue

<template>
  <div id="app">
    <Time1 :miankey="msg"/>
  </div>
</template>

<script>
  import Time1 from './components/Time1'

  export default {
    name: 'App',
    data() {
      return {
        msg: "20xx-xx-xx xx:xx:xx"
      }
    },
    components: {
         Time1
    }
  }
</script>

<style>
 //样式可写可不写
</style>

src/components/Time1

<template>
  <div id="mybtn">
    <p>倒计时</p>
    {{hour}}{{min}}{{sec}}</div>
</template>

<script>
  export default {
    name: "Time1",
    props: ["miankey"],
    data() {
      return {
        hour: "00",
        min: "00",
        sec: "00"
      }
    },
    methods: {
      countdown() {
        var star = new Date().getTime(); //当前时间
        var end = new Date(this.miankey).getTime(); //设定时间
        var time = end - star;

        if (time > 0) {
          this.hour = this.format(parseInt(time / 1000 / 60 / 60));
          this.min = this.format(parseInt(time / 1000 / 60 % 60));
          this.sec = this.format(parseInt(time / 1000 % 60));
          var t = this;
          setTimeout(function() {
            t.countdown();
          }, 1000);

        } else {
          alert("时间到!");
        }
      },
      format(obj) {
        if (obj < 10) {
          return "0" + obj;
        } else {
          return obj;
        }
      }
    },
    mounted() {
      this.star = new Date().getTime();
      this.countdown();
    }
  }
</script>

<style>
  #mybtn {
    background-color: aliceblue;
    width: 500px;
    height: 300px;
  }
</style>

PS:项目目录
在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值