美文网首页
用lodash实现js时间戳内的倒计时

用lodash实现js时间戳内的倒计时

作者: Ann_l | 来源:发表于2018-01-31 21:30 被阅读0次

    公司业务用server返回unix格林时间作为当前时间,同时将返回截止时间

     <template>
      <div></div>
    </template>
    <script type="text/babel">
      /* eslint-disable */
      import axios from 'axios'
      import {GroupTitle, Swipeout, SwipeoutItem, SwipeoutButton, XButton} from 'vux'
    
      export default {
        components: {
        },
        data() {
          return {
            interval: null
          }
        },
        mounted() {
          axios.get('http://172.16.118.54:3030/unixTest').then(res => {
            console.log('axios.get', res)
            const a = Moment(Moment.unix(res.data.deadLine))
            const b = Moment(Moment.unix(res.data.nowServer))
            const diff = a.diff(b)
            const duration = Moment.duration(diff)
            this.interval = setInterval(() => {
              const thisDuration = duration.subtract(1, 's')
              console.log(`${thisDuration.get('days')*24+thisDuration.get('hours')}/${thisDuration.get('minutes')}/${thisDuration.get('seconds')}`)
            }, 1000)
          })
        },
        computed: {},
        destroyed() {
          clearInterval(this.interval)
        },
        methods: {
        },
        created() {
    
        }
      }
    </script>
    <style lang='scss' scoped>
    </style>
    
    

    相关文章

      网友评论

          本文标题:用lodash实现js时间戳内的倒计时

          本文链接:https://www.haomeiwen.com/subject/vqzlzxtx.html