Bootstrap

如何在el-date-picker上实现初始值

如何在el-date-picker上实现初始值

1.主要在el-date-picker 上添加一个数组 :default-value=“this.searchCriteriaInfo.returnVisit”
 <el-date-picker
    clearable
    v-model="searchCriteriaInfo.returnVisit"
    :default-value="this.searchCriteriaInfo.returnVisit"
    type="daterange"
    placeholder="请选择回访周期"
    class="inputWidth"
    format="yyyy-MM-dd"
    value-format="yyyy-MM-dd"
    @change="returnVisitDateChange"
    start-placeholder="开始日期"
    range-separator="-"
    end-placeholder="结束日期"
    >
  </el-date-picker>
2.在data里面定义 一个空数组
 private searchCriteriaInfo: any = {
   returnVisit: [],
   violationType: ''
 }
3.初始化 时间 页面上就有了初始化的值了
 private mounted() {
   this.initEacharts()
    // 初始化页面上的值
   this.searchCriteriaInfo.returnVisit.push(this.getyesterday(),this.getyesterday())

  }
4.方法用于获取昨天的时间
  // 获取昨天的时间
 private getyesterday() {
   let time = (new Date).getTime() - 24 * 60 * 60 * 1000;
   let yesterday: any = new Date(time);
   let month = yesterday.getMonth();
   let day = yesterday.getDate();
   yesterday = yesterday.getFullYear() + "-" + (yesterday.getMonth() > 9 ? (yesterday.getMonth() + 1) : "0" + (yesterday.getMonth() + 1)) + "-" + (yesterday.getDate() > 9 ? (yesterday.getDate()) : "0" + (yesterday.getDate()));
   return yesterday
 }
;