两个日期选择框所选日期都不能大于今天,第二个日期选择框所选日期在第一个日期之后。效果如下图:
第二个日期只能选择2017-02 ~ (2017-06)本月
<template>
<div class="block">
<span class="demonstration">默认</span>
<el-date-picker
v-model="value1"
type="month"
placeholder="选择日期"
:picker-options="pickerOptions0">
</el-date-picker>
</div>
<div class="block">
<span class="demonstration">默认</span>
<el-date-picker
v-model="value2"
type="month"
placeholder="选择日期"
:picker-options="pickerOptions1">
</el-date-picker>
</div>
</template>
<script>
export default {
data() {
let that = this;
return {
value1: '',
value2: '',
pickerOptions0: {
disabledDate(time) {
return time.getTime() > Date.now() - 8.64e7;
}
},
pickerOptions1: {
disabledDate(time) {
return time.getTime() > Date.now() - 8.64e7 ||
time.getTime() < new Date(that.value1).getTime();
}
},
};
}
};
</script>
本文介绍如何使用Element UI组件库中的日期选择器限制用户选择的日期范围,确保第一个选择的日期不大于当前日期,且第二个选择的日期在第一个之后且不大于当前日期。
1621

被折叠的 条评论
为什么被折叠?



