wepy 카운트다운 코드 구현

1971 단어 위챗 애플릿
카운트다운 구성 요소:



  import wepy from 'wepy';

  export default class Daojishi extends wepy.component {
    props = {
        djstime: {
            type: Number,
            default: 'null',
            twoWay: true
        }
    };

    data = {
        couent: ''
    };

    countdown(num){
        let that = this; 
        that.couent = that.dateformat(num) 
        that.$apply()
        console.log(that.dateformat(num))
        if (num <= 0) {
            that.couent = '    '
            return
        }
        setTimeout(function() {
            let newnum = num-1
            that.countdown(newnum)
        }, 1000)
    }

    dateformat(microSecond) {
        var second = Math.floor(microSecond)
        var hr = this.fillZeroPrefix(Math.floor(second / 3600))
        var min = this.fillZeroPrefix(Math.floor((second - hr * 3600) / 60))
        var sec = this.fillZeroPrefix((second - hr * 3600 - min * 60))// equal to => var sec = second % 60;
        return hr + ':' + min + ':' + sec 
    }

    fillZeroPrefix(num) {    
        return num < 10 ? '0' + num : num
    }

    onLoad() { 
        var num = this.$data.djstime
        console.log(num)
        var that = this;
        this.countdown(num)
    };

    onHide(){
        
    }

    onShow() { };
  }



구성 요소 참조:


    
    import wepy from 'wepy'  
    import djs from '../../components/daojishi'

    export default class Time extends wepy.page {    
        config = {      
            navigationBarTitleText: '   '
        }
        components = {
            Djs: djs,
        }
        onLoad() {}
        
        data = {
            clock1: 3600,
        }
    }

 

좋은 웹페이지 즐겨찾기