组件的使用:
<el-date-picker
v-model="time"
type="daterange"
range-separator="至"
start-placeholder="开始日期"
end-placeholder="结束日期"
format="yyyy-MM-dd"
value-format="yyyy-MM-dd"
:picker-options="pickerOptions"
></el-date-picker>
参考:picker-options、getTime()
注意:disabledDate返回为true会禁选某日期,反之则可选。
1、限制开始时间前后可选范围(3年)
data(){
return {
year3: 1000 * 60 * 60 * 24 * 365 * 3,
pickerMindate: null,
pickerOptions: {
onPick: ({ maxDate, minDate }) => {
if (minDate && this.pickerMindate) {
this.pickerMindate = null;
} else if (minDate) {
this.pickerMindate = minDate.getTime();
}
},
disabledDate: time => {
if (this.pickerMindate) {
return (
time.getTime() > this.pickerMindate + this.year3 ||
time.getTime() < this.pickerMindate - this.year3
)
}
return false;
}
}
}
}