当前位置:网站首页>disabledDate 日期选择器 datePicker
disabledDate 日期选择器 datePicker
2022-08-05 05:24: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.30前不可选
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.11前不可选,2022.5.8后面不可选
return time.getTime() > new Date(2022, 5, 8) || time.getTime() < new Date(2021, 11, 11);
}
}
};
}
案例
**需求描述:**起止日期,取值范围在3个月内,并且不能选择超过当天的时间![[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-8Wr7CHNb-1654686674837)(C:\Users\huawei\AppData\Roaming\Typora\typora-user-images\image-20220608184249187.png)]](/img/94/a14ee1e8ff4b2136afdbd816e980e1.png)
实现代码:
<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>
边栏推荐
- [Day5] Soft and hard links File storage, deletion, directory management commands
- 深度 Zabbix 使用指南——来自惨绿少年
- 从“双卡双待“到”双通“,vivo率先推动DSDA架构落地
- I/O performance and reliability
- LeetCode Interview Questions
- Advantages of overseas servers
- 入职前,没想到他们玩的这么花
- What are some things that you only know when you do operation and maintenance?
- 单臂路由与三成交换机
- 增长:IT运维发展趋势报告
猜你喜欢
随机推荐
VLAN详解及实验
Apache configure reverse proxy
千亿IT运维市场,产品要凭实力说话
static routing
Dsf5.0 bounced points determine not return a value
[问题已处理]-jenkins流水线checkout超时
network issue?Service packet loss?This is enough
vim教程:vimtutor
IP地址及子网的划分
CIPU, what impact does it have on the cloud computing industry?
VRRP概述及实验
Growth: IT Operations Trends Report
IP packet format (ICMP protocol and ARP protocol)
TCP/IP four-layer model
sql server 重复值在后面计数
[Day1] (Super detailed steps) Build a soft RAID disk array
spark source code - task submission process - 3-ApplicationMaster
运维工程师,快来薅羊毛
I/O性能与可靠性
有哪些事情是你做了运维才知道的?



![[Day1] VMware software installation](/img/24/20cc77e904dbe7dc1b5224c64d6329.png)





