首页  >  问答  >  正文

javascript - vue 组件参数问题

var down = {
        template:'<span :endTime="endTime" :callback="callback" :endText="endText"><slot>{{content}}</slot></span>',
        data(){
           return {
            content: "",
           }
        },
        props:{
            endTime:{
                type: String,
                required:true,
                default :""
            },
            endText:{
               type : String,
               default:"已结束"
            },
            callback : {
                type : Function,
                default :""
            }
        },
        created() {
            console.log(app);
            // let endTime=this.$route.query.id;
        },
        mounted () {
          this.countdowm(this.endTime)
        },
        methods: {
           countdowm(timestamp){
            let self = this;
            let timer = setInterval(function(){
                let nowTime = new Date();
                let endTime = new Date(timestamp * 1000);
                let t = endTime.getTime() - nowTime.getTime();
                if(t>0){
                    let day = Math.floor(t/86400000);
                    let hour=Math.floor((t/3600000)%24);
                    let min=Math.floor((t/60000)%60);
                    let sec=Math.floor((t/1000)%60);
                    hour = hour < 10 ? "0" + hour : hour;
                    min = min < 10 ? "0" + min : min;
                    sec = sec < 10 ? "0" + sec : sec;
                    let format = '';
                    if(day > 0){
                       format =  `${day}天${hour}小时${min}分${sec}秒`;
                    }
                    if(day <= 0 && hour > 0 ){
                       format = `${hour}小时${min}分${sec}秒`;
                    }
                    if(day <= 0 && hour <= 0){
                       format =`${min}分${sec}秒`;
                    }
                    self.content = format;
                    }else{
                      clearInterval(timer);
                      self.content = self.endText;
                      self._callback();
                    }
                 },1000);
               },
               _callback(){
               if(this.callback && this.callback instanceof Function){
                     this.callback(this);
                 }
            }
        }
    }
<count-down endTime="1497004418" :callback="callback"  endText="已经结束了"></count-down>

vue 通过count-down组件传入数据,this.endTime 无法获取到传入数据,现想得到参数,并且可以参数

大家讲道理大家讲道理2731 天前565

全部回复(3)我来回复

  • ringa_lee

    ringa_lee2017-05-19 10:15:47

    timestamp是string类型的timestamp * 1000能得出数据?

    回复
    0
  • 大家讲道理

    大家讲道理2017-05-19 10:15:47

    endTime 对应的是 end-time

    回复
    0
  • PHPz

    PHPz2017-05-19 10:15:47

    template写法有误啊.
    span是html原生html标签又不是vue组件.怎么可能支持props了.

    回复
    0
  • 取消回复