Vue组件在安装时设置数据

时间:2018-04-16 08:27:30

标签: javascript datepicker vuejs2 vue-component

我希望在安装组件时将临时数据设置为vue组件。并在需要时使用它。在代码下面创建日期选择器并将该对象存储在 vue.obj 中并希望在使用时节目改为真。但它没有奏效。 请帮忙。

Vue.component('date-picker', {
template: "<input type='text' value='obj' class='form-control' placeholder='select date of birth' v-validate=\"'required'\" model='date'>",
props: ['date','show','obj'],
mounted: function() {
    var self = this;
    this.obj = $(this.$el).datepicker({
        onSelect: function(date) {
            self.$emit('update-date', date);
            $(self.$refs.datepicker).trigger('change');
        },
        changeYear: true,
        changeMonth: true,
        dateFormat: "dd/mm/yy",
        yearRange: '1900:' + new Date().getFullYear(),
        maxDate: new Date()
    });
},
watch:{
    show:function(newShow,oldShow){
        console.log(this);
        if(newShow && this.obj){
            this.obj.datepicker("show");
        }
    }
}
});

0 个答案:

没有答案