element 日期时间组件如何限制选择范围只在一个月以内?
代码实现:
HTML部分:
<el-date-picker unlink-panels :picker-options="pickerOptions" v-model="qualityInspectionTime" style="width: 240px" value-format="yyyyMMdd" type="daterange" range-separator="至" start-placeholder="开始时间" end-placeholder="结束时间" @change="datechange"></el-date-picker>
JS部分:
data() {
return {
selectDate: '',
// 日期时间范围在一个月以内
pickerOptions: {
onPick: ({ maxDate, minDate }) => {
this.selectDate = minDate.getTime()
if (maxDate) {
this.selectDate = ''
}
},
disabledDate: (time) => {
if (this.selectDate !== '') {
const one = 30 * 24 * 3600 * 1000
const minTime = this.selectDate - one
const maxTime = this.selectDate + one
return time.getTime() < minTime || time.getTime() > maxTime
}
}
},
}
}