Requirement: The date can only be up to today, and the date span cannot exceed one month
Template section
<el-date-picker v-model="dateRange" type=" dateRange" :picker-options="pickerOptions" placeholder=" placeholder=" placeholder=" > </el-date-picker>Copy the code
Js part
Moment method reference: momentjs.cn/docs/#/mani…
pickerOptions: {
onPick: ({
maxDate,
minDate
}) = >{
this.pickerMinDate = minDate.getTime();
if (maxDate) {
this.pickerMinDate = ''
}
},
disabledDate: time = >{
if (this.pickerMinDate !== '') {
let maxTime = new Date(moment(this.pickerMinDate).add(1, 'months')).getTime();
if (maxTime > new Date()) {
maxTime = new Date()
}
return time.getTime() > maxTime || time.getTime() < new Date('2019-01-01 00:00:00').getTime();
}
return time.getTime() > Date.now() || time.getTime() < new Date('2019-01-01 00:00:00').getTime();
}
}
Copy the code