当前位置:网站首页>DisabledDate date picker datePicker
DisabledDate date picker datePicker
2022-08-05 06:22:00 【MoXinXueWEB】
单选
<el-date-picker v-model="endDate" :picker-options="endDateOpt"></el-date-picker>
data() {
return {
startDate: null,
endDate: null,
endDateOpt: {
disabledData: (time) => {
// 2021.12.30Not optional before
return time.getTime() < new Date(2021, 11, 30);
}
}
}
}
区间daterange或datetimerange情况
<el-date-picker v-model="value" type="daterange"
:picker-options="pickerOptions">
</el-date-picker>
data() {
return {
value: '',
pickerOptions: {
disabledDate: (time) => {
// 注意是||不是&&
// 表示2021.12.11Not optional before,2022.5.8The latter is not optional
return time.getTime() > new Date(2022, 5, 8) || time.getTime() < new Date(2021, 11, 11);
}
}
};
}
案例
**需求描述:**起止日期,取值范围在3个月内,And can not select more than the time of the day
实现代码:
<template>
<div>
<span>起止日期:</span>
<el-date-picker v-model="startdate" type="date" placeholder="开始日期" :picker-options="pickerOption0" value-format="yyyyMMdd" format="yyyyMMdd">
</el-date-picker> -
<el-date-picker v-model="enddate" type="date" placeholder="结束日期" :picker-options="pickerOption1" value-format="yyyyMMdd" format="yyyyMMdd">
</el-date-picker>
</div>
</template>
<script>
export default {
data() {
return {
startdate: '',
enddate: ''
}
},
computed: {
pickerOption0() {
let obj = {}
obj.disabledDate = time => {
if (this.enddate != '' && this.enddate != null) {
let value = this.enddate.replace(/(\d{4})(\d{2})(\d{2})/, "$1-$2-$3");
let d = new Date(value);
d.setMonth(d.getMonth() - 3);
return time.getTime() > new Date(value) || time.getTime() < d;
} else {
return time.getTime() > new Date();
}
};
return obj;
},
pickerOption1() {
let obj = {}
obj.disabledDate = time => {
if (this.startdate != '' && this.startdate != null) {
let value = this.startdate.replace(/(\d{4})(\d{2})(\d{2})/, "$1-$2-$3");
let d = new Date(value);
d.setMonth(d.getMonth() + 3);
return time.getTime() > d || time.getTime() > new Date(value);
} else {
return time.getTime() > new Date();
}
};
return obj;
},
},
}
</script>
边栏推荐
猜你喜欢
随机推荐
IP address and subnet division
Xiaodu Xiaodu is here!
深度 Zabbix 使用指南——来自惨绿少年
Complete mysql offline installation in 5 minutes
媒体查询、rem移动端适配
What's the point of monitoring the involution of the system?
Network wiring and digital-to-system conversion
错误类型:反射。ReflectionException:无法设置属性“xxx”的“类”xxx”与价值“xxx”
解决这三大问题,运维效率将超90%的医院
Hugo搭建个人博客
Four ways to obtain Class objects through reflection
TCP/IP four-layer model
The Servlet to jump to the JSP page, forwarding and redirection
Take you in-depth understanding of cookies
运维的高光时刻,从智能化开始
Servlet跳转到JSP页面,转发和重定向
idea 常用快捷键
Into the pre-service, thought they play so flowers
云计算——osi七层与TCP\IP协议
原生JS带你了解数组方法实现及使用