How the element-ui date Selector gives the default time

look at the document and say that the default time displayed when default-value is opened
but it has no effect. How should the format be written

Mar.28,2021

just assign a value to the v-model of el-date-picker without the default-value assignment code

 var now = new Date();
 var startDate = new Date(Date.UTC(now.getFullYear(), now.getMonth(), now.getDate())).toISOString().slice(0, 10);
  var endDate = new Date(Date.UTC(now.getFullYear(), now.getMonth(), now.getDate()+1)).toISOString().slice(0, 10);
 this.date=[];
 this.date.push(startDate)
 this.date.push(endDate)

element ui time selector

<el-date-picker
  size='small'
  value-format="yyyy/MM/dd"
  v-model="date"
  placeholder=""
  type="date">
</el-date-picker>

vue data binding

export default {
    data () {
        return {
            date: new Date() //   
        }
    }
}

< el-form-item label= "start date" prop= "start_time" >

          <el-date-picker
            lable=""
            v-model="formData.start_time"
            type="date"
            placeholder=""
            style="width: 100%;"
            format="yyyy-MM-dd "
            value-format="yyyy-MM-dd"
            @change="dateChange"
          >
          </el-date-picker>
        </el-form-item>          

js writes
data () {
return {
formData: {

      start_time: ''

}
}
created () {
this.getTime ()
},
method: {
getTime () {

    let date = new Date()
    let y = date.getFullYear()
    let m = date.getMonth() + 1
    let d = date.getDate()
    console.log(d)
    let time = y + '-' + m + '-' + d
    this.formData.start_time = time
  }

}
so you can set the default time. Welcome to adopt

.

didn't you write the number of milliseconds that can be parsed by new Date


those who ask questions directly without the code are all hooligans


:default-value    // " : " 

did the landlord solve the same problem?


take a look at your requirement, which is very similar to a recent requirement on my side. Element's official document says that the new Date () acquisition time is indeed like this, but it is actually very simple to do some processing after getting it.

export default {
 data() {
        let showDate =new Date();
        let seperator ='-';
        let year = showDate.getFullYear();
        let month = showDate.getMonth() + 1;
        let day =showDate.getDate();
        var strDate = showDate.getDate();
        if (month >= 1 && month <= 9) {
            month = "0" + month;
        }
        if (strDate >= 0 && strDate <= 9) {
            strDate = "0" + strDate;
        }
        let currentdate = year + seperator + month + seperator + strDate;
      return {
        TimeSpace: [currentdate,currentdate],//
        }
     }
   }

this is in the form of a time interval. Put it in an array. If it is divided into the start time and the end time, it corresponds to the start_time:currentdate,end_time:currentdate,. Hope it can help you

.
Menu