vue+ElementUI 时间选择器默认为当前时间年月日

1.html部分

<el-form-item label="录入时间:" prop="recordTime">
     <el-date-picker type="date" value-format="yyyy-MM-dd" placeholder="选择日期" v-model="ruleForm.recordTime" style="width: 100%;"></el-date-picker>
</el-form-item>

2.js部分

data(){
    return {
        ruleForm:{
            recordTime: "",
        }
    }
},
created(){
    this.getNowTime()
},
methods:{
    getNowTime() {
       var now = new Date();
       var year = now.getFullYear(); //得到年份
       var month = now.getMonth(); //得到月份
       var date = now.getDate(); //得到日期
       month = month + 1;
       month = month.toString().padStart(2, "0");
       date = date.toString().padStart(2, "0");
       var defaultDate = `${year}-${month}-${date}`;
       this.$set(this.ruleForm, "recordTime", defaultDate);
   },
}

  

  

posted @ 2021-08-09 16:49  webCandy呀  阅读(3755)  评论(0编辑  收藏  举报