<template>
<el-date-picker
v-model="time"
type="datetimerange"
range-separator="至"
start-placeholder="开始日期"
end-placeholder="结束日期"
:picker-options="pickerOptions"
>
</el-date-picker>
</template>
data() {
return {
time:'',
choiceDate:null,
pickerOptions: {
onPick: ({ maxDate, minDate }) => {
// 把选择的第一个日期赋值给一个变量。
this.choiceDate = minDate.getTime()
// 如何你选择了两个日期了,就把那个变量置空
if (maxDate) this.choiceDate = ''
},
disabledDate: time => {
// 如何选择了一个日期
if (this.choiceDate) {
console.log(time.getTime(),66,this.choiceDate);
// 7天的时间戳
const one = 6 * 24 * 3600 * 1000
// 当前日期 - one = 7天之前
const minTime = this.choiceDate - one
// 当前日期 + one = 7天之后
const maxTime = this.choiceDate + one
return (
time.getTime() < minTime ||
time.getTime() > maxTime
)
}else{
return false
}
}
},
}
element-ui 时间日期选择器限制选择七天范围内日期.
最新推荐文章于 2024-01-16 16:22:43 发布