需求:选择任意时间后,限制后面可选时间范围
<el-date-picker
v-model="dateArr"
type="daterange"
value-format="yyyy-MM-dd"
range-separator="至"
start-placeholder="开始日期"
end-placeholder="结束日期"
:picker-options="pickerOptions"
></el-date-picker>
export default {
data () {
return {
pickerOptions: {
//首选获取当前开始选择时间
onPick: ({ maxDate, minDate }) => {
this.selectData = minDate.getTime()
if (maxDate) {
// 解除限制
this.selectData = ''
}
},
disabledDate: (time) => {
if (this.selectData) {
const curDate = this.selectData
const three = 10 * 24 * 3600 * 1000 // 时间范围
const threeMonths = curDate + three // 开始时间 + 时间范围
return time.getTime() < curDate || time.getTime() > threeMonths
}
},
},
selectData: '',
dateArr: [],
}
}
},