Vue+element ui 表单中日期选择器范围控制
Vue+element ui 表单中日期选择器范围控制
·
1.页面(单个日期)
<el-form ref="form" :model="form" :rules="rules" label-width="80px">
<el-form-item label="开始时间" prop="beginDate">
<el-date-picker
v-model="form.beginDate"
type="date"
placeholder="选择日期"
value-format="yyyy-MM-dd"
:picker-options="beginDateOption"
:clearable="false"
></el-date-picker>
</el-form-item>
<el-form-item label="结束时间" prop="endDate">
<el-date-picker
v-model="form.endDate"
type="date"
placeholder="选择日期"
value-format="yyyy-MM-dd"
:picker-options="endDateOption"
:clearable="false"
></el-date-picker>
</el-form-item>
</el-form>
2.js (单个日期)
<script>
export default {
data() {
return {
//开始时间限制
beginDateOption: {
disabledDate: (time) => {
if (this.form.endDate) {
return time.getTime() > new Date(this.form.endDate).getTime();
}
},
},
//结束时间限制
endDateOption: {
disabledDate: (time) => {
if (this.form.beginDate) {
return (
time.getTime() <
new Date(this.form.beginDate).getTime() - 24 * 3600 * 1000
);
}
},
},
};
},
};
</script>
3.页面(日期范围)
<el-date-picker
v-model="dateRange"
style="width: 90%"
value-format="yyyy-MM-dd"
type="daterange"
range-separator="-"
start-placeholder="开始日期"
end-placeholder="结束日期"
:picker-options="pickerOptions"
:clearable="false"
:editable="false"
></el-date-picker>
4.js(日期范围)
<script>
export default {
data() {
return {
pickerOptions: {
disabledDate(time) {
return time.getTime() < Date.now() - 8.64e7;//对小于开始日期范围禁用,否则反之即可
},
}
};
}
};
</script>
更多推荐
已为社区贡献6条内容
所有评论(0)