以下方法适用daterange类型组件
1.跨度一年但不限制时间
pickerOptions: {
disabledDate: (time) => {
const choiceDateTime = new Date(this.selectDate).getTime();
const minTime = new Date(choiceDateTime).setMonth(new Date(choiceDateTime).getMonth() - 12);
const maxTime = new Date(choiceDateTime).setMonth(new Date(choiceDateTime).getMonth() + 12);
if (this.selectDate) {
return time.getTime() < minTime || time.getTime() > maxTime;
}
return false;
},
onPick: ({ maxDate, minDate }) => {
this.selectDate = minDate.getTime();
if (maxDate) {
this.selectDate = '';
}
}
}
2.跨度一年但是最大不能超过明天
pickerOptions: {
disabledDate: (time) => {
const selectDateTime = new Date(this.selectDate).getTime();
const minDate = new Date(selectDateTime).setMonth(new Date(selectDateTime).getMonth() - 12);
const maxDate = new Date(selectDateTime).setMonth(new Date(selectDateTime).getMonth() + 12);
const min = minDate;
const newDate = new Date(new Date().toLocaleDateString()).getTime() + 24 * 60 * 60 * 1000 - 1;
const max = newDate < maxDate ? newDate : maxDate;
if (this.selectDate) {
return time.getTime() < min || time.getTime() > max;
}
return time.getTime() > newDate;
},
onPick: ({ maxDate, minDate }) => {
this.selectDate = minDate.getTime();
if (maxDate) {
this.selectDate = '';
}
}
}