vue倒计时

99封情书 提交于 2020-01-08 20:47:00
export default {
  name: "HelloWorld",
  data() {
    return {
      endTime: "2020-01-10 19:00:00",
      day: "",
      hour: "",
      min: "",
      second: ""
    };
  },
  created() {
    this.getReserTime();
  },
  methods: {
    dateFormate(num){
      if(num<10){
        return '0'+num
      }else{
        return num
      }
    },
    getReserTime() {
      let interval = setInterval(() => {
        let nowTime = new Date().getTime();
        let endTime = new Date(this.endTime).getTime();
        let chaTime = (endTime - nowTime) / 1000;
        this.day = parseInt(chaTime / (60 * 60 * 24));
        this.hour = parseInt((chaTime % (60 * 60 * 24)) / 3600);
        this.min = parseInt(((chaTime % (60 * 60 * 24)) % 3600) / 60);
        this.second = parseInt(((chaTime % (60 * 60 * 24)) % 3600) % 60);
      }, 1000);
    }
  }
};
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!