当前位置:网站首页>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>
边栏推荐
- 微信小程序页面跳转传参
- LeetCode面试题
- Introductory document 05-2 use return instructions the current task has been completed
- flink cdc 目前支持Gauss数据库源吗
- Three modes of vim
- By solving these three problems, the operation and maintenance efficiency will exceed 90% of the hospital
- Getting Started Document 01 series in order
- Getting Started 04 When a task depends on another task, it needs to be executed in sequence
- Spark source code - task submission process - 4-container to start executor
- ACLs and NATs
猜你喜欢

错误类型:反射。ReflectionException:无法设置属性“xxx”的“类”xxx”与价值“xxx”

What's the point of monitoring the involution of the system?

Unity realizes first-person roaming (nanny-level tutorial)

正则表达式小实例--验证邮箱地址

Switch principle

账号与权限管理
![[Day6] File system permission management, file special permissions, hidden attributes](/img/ec/7fb3fa671fac8abf389844c0f4fbe7.png)
[Day6] File system permission management, file special permissions, hidden attributes

带你深入了解Cookie

What are some things that you only know when you do operation and maintenance?

线上问题排查流程
随机推荐
带你深入了解Cookie
Getting Started 11 Automatically add version numbers
时间复杂度和空间复杂度
网络不通?服务丢包?看这篇就够了
To TrueNAS PVE through hard disk
vim教程:vimtutor
【Day8】RAID Disk Array
Small example of regular expression--validate email address
network issue?Service packet loss?This is enough
The problem of calling ds18b20 through a single bus
Mongodb query analyzer parsing
通过反射获取Class对象的四种方式
Hugo builds a personal blog
运维工程师,快来薅羊毛
vim的三种模式
程序员应该这样理解I/O
逻辑卷创建
NAT实验
[问题已处理]-jenkins流水线checkout超时
Getting Started 05 Using cb() to indicate that the current task is complete