演示效果
只能选择同一天日期
<el-date-picker
v-model="update.form.value"
@change="selectData"
type="datetimerange"
value-format="yyyy-MM-dd HH:mm:ss"
range-separator="至"
start-placeholder="开始日期"
:picker-options="pickerOptions"
end-placeholder="结束日期"
:default-time="['00:00:00', '00:00:00']"
></el-date-picker>
methods: {
selectData(e) {
if (e === null) {
this.pickerOptions.startDate = null;
}
},
}
data () {
return {
pickerOptions: {
startDate: null,
disabledDate: (time) => {
if (
this.pickerOptions.startDate === undefined ||
this.pickerOptions.startDate === null
) {
return time.getTime() < Date.now() - 8.64e7;
} else {
return (
time.getTime() >
this.pickerOptions.startDate.getTime() + 86399000 ||
time.getTime() < this.pickerOptions.startDate.getTime()
);
}
},
onPick: (dateRange) => {
this.pickerOptions.startDate = dateRange.minDate;
if (dateRange.maxDate) {
this.pickerOptions.startDate = null;
}
},
},
}
}
限制选择今天及之后的日期时间
<el-date-picker
v-model="update.form.value"
type="datetimerange"
value-format="yyyy-MM-dd HH:mm:ss"
range-separator="至"
start-placeholder="开始日期"
:picker-options="pickerOptions"
end-placeholder="结束日期"
:default-time="['00:00:00', '00:00:00']"
></el-date-picker>
data() {
return {
pickerOptions: {
startDate: null,
disabledDate: (time) => {
if (
this.pickerOptions.startDate === undefined ||
this.pickerOptions.startDate === null
) {
return time.getTime() < Date.now() - 8.64e7;
} else {
return
time.getTime() < Date.now() - 8.64e7
}
},
onPick: (dateRange) => {
this.pickerOptions.startDate = dateRange.minDate;
if (dateRange.maxDate) {
this.pickerOptions.startDate = null;
}
},
},
}
}