1描述
设置时间可选值为第一次选择的时间点上下一周即可
效果如下
代码如下
<el-date-picker
v-model="searchDateRange"
type="daterange"
:picker-options="pickerOptions"
format="yyyy-MM-dd"
value-format="yyyy-MM-dd"
range-separator="至"
start-placeholder="开始日期"
end-placeholder="结束日期">
</el-date-picker>
data中:
pickerMinDate:'',
pickerOptions: {
onPick: (time) => {
// this.pickerMinDate = time.minDate;
if(time.minDate && !time.maxDate){
this.pickerMinDate=time.minDate; //将第一次选中值保存
}
if(time.maxDate){
this.pickerMinDate=null;
}
},
disabledDate:(time)=> {
if (this.pickerMinDate) {
const day1 = 7 * 24 * 3600 * 1000
let maxTime = this.pickerMinDate.getTime() + day1
let minTime = this.pickerMinDate.getTime() - day1
return time.getTime() > maxTime || time.getTime() < minTime
}else{
return time.getTime() > Date.now()+1 * 24 * 3600 * 1000
}
}
}