1.限制条件用到pickerOptions
代码如下
<template>
<div>
<el-date-picker
v-model="dateRange"
type="daterange"
range-separator="至"
start-placeholder="开始日期"
end-placeholder="结束日期"
:picker-options="pickerOptions"
/>
</div>
</template>
<script>
export default {
data() {
const that = this
return {
dateRange: [],
curDate: '',
pickerOptions: {
onPick: ({ maxDate, minDate }) => {
that.curDate = minDate.getTime()
if (maxDate) {
that.curDate = ''
}
},
disabledDate(time) {
if (that.curDate) {
// 限制前后三十天
const one = 30 * 24 * 3600 * 1000
const minTime = that.curDate - one
const maxTime = that.curDate + one
return time.getTime() < minTime || time.getTime() > maxTime
}
}
}
}
}
}
</script>