• 倒计时


    <template>
      <span style="color: #ff5454;">{{time}}</span>
    </template>
    
    
    
    <script>
      export default{
        data () {
          return {
            time : '',
            flag : false
          }
        },
        mounted () {
          let time = setInterval(()=>{
            if(this.flag == true){
              clearInterval(time)
            }
            this.timeDown()
          },500)
        },
        props : {
          endTime : {
            type : String
          }
        },
        methods : {
          timeDown () {
            const endTime = new Date(this.endTime)
            const nowTime = new Date();
            let leftTime = parseInt((endTime.getTime()-nowTime.getTime())/1000)
            let d = parseInt(leftTime/(24*60*60))
            let h = this.formate(parseInt(leftTime/(60*60)%24))
            let m = this.formate(parseInt(leftTime/60%60))
            let s = this.formate(parseInt(leftTime%60))
            if(leftTime <= 0){
              this.flag = true
              this.$emit('time-end')
            }
            this.time = `${d}天${h}小时${m}分${s}秒`
          },
          formate (time) {
            if(time>=10){
              return time
            }else{
              return `0${time}`
            }
          }
        }
      }
    </script>
    
    <style scoped>
    </style>
    

      

  • 相关阅读:
    Less的嵌套规则
    作为函数的mixin
    带参数的Mixin
    Less的Mixin
    Less变量
    sticky-css
    javascript copy 复制到粘贴板的方法
    Storage支持率记录
    cookie session 做登录认证
    vue2.x 微信浏览器中遇到的奇难杂症
  • 原文地址:https://www.cnblogs.com/xiaohuohuai/p/14677874.html
Copyright © 2020-2023  润新知