current position:Home>Vue---element-ui--date picker component start time and end time are grayed out

Vue---element-ui--date picker component start time and end time are grayed out

2022-06-24 09:57:50Strawberry chocolate beans

Style effect :
When the start time is selected , Then choose the end time , In the end schedule item , The date before the start time is grayed out and cannot be selected .
 Insert picture description here
Code samples :
If some attributes are not understood , Please refer to the official website Introduction to the time selector component

<el-form :model="createForm" ref="ruleForm" :rules="rules">
 <el-form-item
              label=" Regular time "
              width="400"
              label-width="72px"
              style="margin-bottom: 0px;"
            >
                  <el-form-item
                    :prop="`tipMessageDates`"
                    :rules="rules.tipMessageRuleDates"
                  >
                    <el-date-picker
                      v-model="tipMessageDates.startDate"
                      type="date"
                      :picker-options="startPickerOptions"
                      @focus="onFocus(tipMessageDates)"
                      value-format="yyyy-MM-dd"
                      placeholder=" Starting time "
                    >
                    </el-date-picker
                    ><span style="margin: 0 10px;"> to </span>
                    <el-date-picker
                      v-model="tipMessageDates.endDate"
                      type="date"
                      :picker-options="endPickerOptions"
                      @focus="onFocus(tipMessageDates)"
                      value-format="yyyy-MM-dd"
                      placeholder=" End time "
                    >
                    </el-date-picker>
                  </el-form-item>
                </div>
            </el-form-item>
</el-form>

data(){
    
 return {
    
	 endPickerOptions: any = this.processDate() //  End time grayed out 
   startPickerOptions: any = this.beginDate() //  Start time is grayed out 
   nowDate: any = null //  Currently selected time 
}
}
methods:{
    
 //  Time input is clicked 
  onFocus(data: any) {
    
    this.nowDate = data
  }
 //  Start time is grayed out 
  beginDate() {
    
    let self: any = this
    return {
    
      disabledDate(time: any) {
    
        if (self.nowDate.endDate) {
    
          return new Date(self.nowDate.endDate).getTime() < time.getTime()
        } else {
    
          return false
        }
      }
    }
  }
  //  End time grayed out 
  processDate() {
    
    let self: any = this
    return {
    
      disabledDate(time: any) {
    
        if (self.nowDate.startDate) {
    
          return (
            new Date(self.nowDate.startDate).getTime() - 8.64e7 > time.getTime()
          )
        } else {
    
          return false
        }
      }
    }
  }
}

copyright notice
author[Strawberry chocolate beans],Please bring the original link to reprint, thank you.
https://en.qdmana.com/2022/175/202206240807060742.html

Random recommended