element-ui的年份范围选择器,选择的年份需等于或小于当前年份,选择的年份范围必须在三年之内

写在前面

日期限制处理(禁用),下面我以我这边的需求为例,

选择的年份需等于或小于当前年份
选择的年份范围必须在三年之内

1.限制起始日期小于截止日期
1)根据用户选中的开始日期,置灰不可选的日期范围;

2)如果用户先选择截止日期,再选择的开始日期,且开始日期大于截止日期,清空截止日期;
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

  <div class="min-wid data-flex-start" ><span class="with-hide"></span><span class="with-d with-s"></span><div class="year-range-picker"><el-date-pickerv-model="dateList[0]":picker-options="startDatePicker"type="year"placeholder="选择开始年"size="mini"class="year-picker"format="yyyy"value-format="yyyy"@change="handleDateChange"/><span class="range-word"></span><el-date-picker:key="randomKey "v-model="dateList[1]":picker-options="endDatePicker":default-value="dateDefaultShow"type="year"placeholder="选择结束年"size="mini"class="year-picker"value-format="yyyy"/></div></div>
 data() {return {randomKey: 0,startDatePicker: this.beginDate(),endDatePicker: this.processDate(),dateDefaultShow: '', // 日期选择器的日期默到选择的年份datatimeStr: {dateBegin: '',endDataDate: ''},minNowDate: '',maxNowDate: '',dateList: ['', '']}}
 methods: {// 获取日期 disabledDate 函数用于定义哪些日期应该被禁用。禁止选择大于特定日期的日期。// 选择年份范围选择时开始时间不能大于结束时间,结束时间不能小于开始时间// 提出开始时间必须小于提出结束时间beginDate() {const self = thisreturn {disabledDate(time) {if (self.dateList[1] !== '') {const fixedTime = new Date(time)return fixedTime.getFullYear() > self.dateList[1]}}}},// 提出结束时间必须大于提出开始时间processDate() {const self = thisreturn {disabledDate(time) {if (self.dateList[0] !== '') {const fixedTime = new Date(time)if ((Number(self.maxNowDate) - Number(self.dateList[0])) <= 2) {return fixedTime.getFullYear() > self.maxNowDate || fixedTime.getFullYear() < self.dateList[0]} else {return fixedTime.getFullYear() > (self.maxNowDate - (Number(self.maxNowDate) - Number(self.dateList[0])) + 2) || fixedTime.getFullYear() < self.dateList[0]}}}}},// 获取最大日期getMaxDate() {getDataDate().then(res => {// 默认结束年为有数据的最近年,默认开始年为默认结束年-2,即默认时间范围为3年this.maxNowDate = res.slice(0, 4)this.minNowDate = this.maxNowDate - 2this.dateList[0] = this.minNowDate.toString()this.dateList[1] = this.maxNowDate// 强制刷新this.$forceUpdate()}).catch(err => {console.log(err)})},// 当开始日期改变时的处理函数// 如果截止日期早于开始日期3年以上,将截止日期清空handleDateChange() {// 当选择的开始日期比结束日期早三年以上时,清空结束日期if (this.dateList[1] - 2 > this.dateList[0]) {this.dateList[1] = ''// 改变数组内的值,强制刷新,清空结束日期的显示this.randomKey = Math.random()}// 日期选择器定位到选择的开始年份this.dateDefaultShow = this.dateList[0]}}
<style scoped>/* 顶部样式 */.card-head{padding:12px 16px;background-color: #fff;position:relative;}/* 数据日期字体样式 */.date-font{color: var(---Gray-6, #78808F);font-family: "PingFang SC";font-size: 12px;font-style: normal;font-weight: 400;line-height: 20px; /* 166.667% */}/*弹性布局:两端对齐 */.data-flex-sabw{display: flex;flex-direction: row;justify-content: space-between;align-items: center;}/* 弹性布局:左对齐*/.data-flex-start {display: flex;flex-direction: row;justify-content: flex-start;align-items: center;}/* 弹性布局:右对齐*/.data-flex-end {display: flex;flex-direction: row;justify-content: flex-end;align-items: center;}.tp-con{width: 100%;height: 56px;box-sizing: border-box;display: flex;padding: 12px 0px;align-items: flex-start;gap: 20px;}/*隐藏显示,占位*/.with-hide {opacity: 0;color: var(---Neutral-8, #292929);font-family: "PingFang SC";font-size: 14px;font-style: normal;font-weight: 400;line-height: 22px; /* 157.143% */}.with-d {width: 24px;}.with-t {width: 80px;}.with-l {width: 38px;}.with-s {box-sizing: border-box;padding-right: 8px;color: var(---Neutral-8, #292929);text-align: right;font-family: "PingFang SC";font-size: 14px;font-style: normal;font-weight: 400;line-height: 22px; /* 157.143% */}.st_line {box-sizing: border-box;margin: 0 2px;width: 9px;height: 22px;color: var(---Gray-6, #78808F);text-align: center;font-family: "PingFang SC";font-size: 14px;font-style: normal;font-weight: 400;line-height: 22px; /* 157.143% */}.min-wid{min-width:160px;}.query-bt {background-color: #00B0B0;color: #FFF;outline: none;}.center-deep{hight: 100%;width: 100%;background-color: #fff;margin-top: 16px;}/deep/ .treeselect-main {width: 204px;line-height: 28px;}/deep/ .vue-treeselect__placeholder {line-height: 28px;}/deep/ .vue-treeselect__control {height: 32px !important;line-height: 32px;border-radius: 4px;}/deep/.vue-treeselect__single-value {font-size: 14px;top: 0%;color: #606266;font-weight: 400;}/deep/.vue-treeselect__input {height: 32px;line-height: 32px;}/*顶部筛选器输入框宽度*//deep/.el-select el-select--small,el-input el-input--small el-input--suffix{width: 100% !important;flex: 1;}/*年范围选择器*/.year-range-picker {color: black;text-align: center;border: 1px solid #dcdfe6;border-radius:4px;line-height: 32px;overflow: hidden;display: flex;margin: 4px 0;}/deep/.el-input--mini .el-input__inner {height: 32px;line-height: 32px;border: none}.range-word {box-sizing: border-box;padding-top: 6px;color: var(---Neutral-8, #292929);text-align: right;font-family: "PingFang SC";font-size: 14px;font-style: normal;font-weight: 400;line-height: 22px;}.year-range-picker .year-picker {max-width: 150px;margin:0;}
</style>

参考文章:ElementUI 年份范围选择器 el-year-picker
点开是关联的组件-基于element-ui的年份范围选择器
vue中element-ui日期选择组件el-date-picker 清空所选时间,会将model绑定的值设置为null 问题 及 限制起止日期范围
vue elementui时间控件,(单框同时选)范围选择周,季,年。
element ui datepicker时间控件实现范围选择周,季,年。
ElementUI年份范围选择器功能实现
element ui的日期选择器动态设定年份,并默认显示在该年份范围的日期时间
vue2、vue3中使用$forceUpdate()

🚀写在最后

希望我的分享能够帮助到更多的人,如果觉得我的分享有帮助的话,请大家一键三连支持一下哦~
❤️原创不易,期待你的关注与支持~
点赞👍+收藏⭐️+评论✍️
😊之后我会继续更新前端学习小知识,关注我不迷路~

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/803056.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

【腾讯云 TDSQL-C Serverless 产品体验】饮水机式使用云数据库

云计算的发展从IaaS&#xff0c;PaaS&#xff0c;SaaS&#xff0c;到最新的BaaS&#xff0c;FasS&#xff0c;在这个趋势中serverless(去服务器化&#xff09; 计算资源发展Physical -> Virtualisation -> Cloud Compute -> Container -> Serverless。 一、背景介绍…

LeetCode 264. 丑数 II

解题思路 三个指针进行遍历&#xff0c;归并排序。 相关代码 class Solution {public int nthUglyNumber(int n) {int temp1;int a[] new int[n];a[0] 1;for(int i0,j0,k0,index1;index<n;index){temp Math.min(a[i]*2,Math.min(a[k]*5,a[j]*3));a[index] temp;if(te…

什么是电子邮件组,为什么要使用它们?

在当今时代&#xff0c;电子邮件无处不在&#xff0c;尤其是对于商业活动而言。电子邮件的重要性不容忽视&#xff0c;因为它在沟通中极为高效。然而&#xff0c;电子邮件也存在降低工作效率和阻碍流程的风险。在这种情况下&#xff0c;电子邮件群组就是最佳的解决方案。什么是…

代码随想录算法训练营第二十九天|491.递增子序列,46.全排列,47.全排列 II

题目&#xff1a;491.递增子序列 给你一个整数数组 nums &#xff0c;找出并返回所有该数组中不同的递增子序列&#xff0c;递增子序列中至少有两个元素。你可以按任意顺序返回答案。 数组中可能含有重复元素&#xff0c;如出现两个整数相等&#xff0c;也可以视作递增序列的一…

VUE路由跳转、传参总结

路由跳转方式有哪些&#xff1f; 在Vue中&#xff0c;路由跳转主要有以下几种方式&#xff1a; 使用router-link组件&#xff1a; <router-link to"/home">Home</router-link>使用编程式导航 // 字符串 this.$router.push(home)// 对象 this.$router.…

大学生拥有一台服务器可以做什么?

云服务器的崭新世界&#xff0c;充满了无限的可能性和激动人心的挑战。无论你是想要建立个人网站、运行定时任务&#xff0c;还是学习Linux系统&#xff0c;云服务器都为你提供了一个极具灵活性和自由度的平台。 让我们一起深入探索&#xff0c;看看拥有一台服务器你可以做些什…

【学习 在服务器上使用bypy直接下载百度云盘的资源。

参考&#xff1a;bypy 具体步骤 step1&#xff1a; pip install bypystep2&#xff1a; bypy info第一次输入该命令&#xff0c; 点击进入网址&#xff0c;点击登陆后&#xff0c;获取token&#xff08;10分钟内有效&#xff09;&#xff0c;然后输入到命令行&#xff1a;…

【linux深入剖析】深入理解基础外设--磁盘

&#x1f341;你好&#xff0c;我是 RO-BERRY &#x1f4d7; 致力于C、C、数据结构、TCP/IP、数据库等等一系列知识 &#x1f384;感谢你的陪伴与支持 &#xff0c;故事既有了开头&#xff0c;就要画上一个完美的句号&#xff0c;让我们一起加油 目录 前言1.磁盘物理结构2.磁盘…

汽车差速器原理?

差速器&#xff08;Differential&#xff09;是汽车传动系统中的重要组成部分&#xff0c;主要作用是允许车辆驱动轮以不同速度旋转&#xff0c;从而使车辆能够顺利转弯并保持稳定性。其基本原理如下&#xff1a; 解决转弯问题&#xff1a; 当车辆转弯时&#xff0c;内侧轮和外…

pnputil卸载Sangfor

pnputil /delete-driver sangforvnic.inf /uninstall Microsoft PnP 工具PNPUTIL [/add-driver <...> | /delete-driver <...> |/export-driver <...> | /enum-drivers |/enum-devices [<...>] | /enum-interfaces [<...>] |/disable-device &l…

Go 实战|使用 Wails 构建轻量级的桌面应用:仿微信登录界面 Demo

概述 本文探讨 Wails 框架的使用&#xff0c;从搭建环境到开发&#xff0c;再到最终的构建打包&#xff0c;本项目源码 GitHub 地址&#xff1a;https://github.com/mazeyqian/go-run-wechat-demo 前言 Wails 是一个跨平台桌面应用开发框架&#xff0c;他允许开发者利用 Go …

C中的函数原型声明、头文件包含的思考

1&#xff09;如果add1.c调用了add2.c中的add2函数&#xff0c;add2.h定义了add2.c中的函数原型&#xff0c;add1.c需包含#include "add2.h"的原因&#xff1f; add1.c既然调用了函数add2&#xff0c;必须知道函数add2的函数原型&#xff0c;否则gcc -c add1.c&…

联想电脑VMware虚拟机VT开启虚拟化

以联想电脑为例。 关机重启&#xff0c; 有的电脑是按F2&#xff0c; 有的是按fnF2 进入BIOS&#xff0c;左右键&#xff0c;选择Configuration&#xff0c; 再上下键选择 Intel Virtual Technology 按回车键&#xff0c;再按上下键选择 Enable &#xff0c;回车确认。 按fn…

Xlinx相关原语讲解导航页面

原语就是对FPGA底层器件的直接调用&#xff0c;与IP功能是类似的&#xff0c;将原语的参数变成IP配置时的GUI界面参数&#xff0c;可能会更加直观。IP的缺陷在于繁杂&#xff0c;比如SelectIO IP内部包含IDDR、ODDR等等IO转换的功能&#xff0c;如果只想使用单沿转双沿一个功能…

ChatGPT全方位解析:如何培养 AI 智能对话技能?

简介 ChatGPT 的主要优点之一是它能够理解和响应自然语言输入。在日常生活中&#xff0c;沟通本来就是很重要的一门课程&#xff0c;沟通的过程中表达的越清晰&#xff0c;给到的信息越多&#xff0c;那么沟通就越顺畅。 和 ChatGPT 沟通也是同样的道理&#xff0c;如果想要C…

[软件使用-Vcftools / Plink ] VCF文件中剔除/提取一个或多个样本,两组方法实现及运算时间比较

官网&#xff1a;VCFtools 参数查看&#xff1a; 提取样本 --keep 剔除样本 --remove # 提取某几个样本 system("vcftools --vcf eg.vcf --keep keep.list --recode --out keep") # keep.list 是由每一行为一个样本ID组成的文件 tips: 运行比较耗时 官网&#xff…

Spring的Bean标签配置IOC和依赖注入详解

目录 spring配置文件详解 spring配置文件详解 spring的依赖注入和控制反转梳理总结&#xff0c;仅供参考 /*** Bean的依赖注入&#xff1a;* ① 创建 UserService&#xff0c;UserService 内部在调用 UserDao的save() 方法* ② 将 UserServiceImpl 的创建权交给 Spring* ③ 从…

Oracle测试10046参数及打印结果

1.1 开启session sql trace alter session set tracefile_identifier10046; alter session set timed_statistics true; --默认是true alter session set statistics_levelall; --实例级别设置需要注意&#xff0c;会消耗大量的CPU alter session set max_…

《关于进一步优化重点文旅场所支付服务 提升支付便利性的通知》发布

为贯彻党中央、国务院决策部署&#xff0c;落实《国务院办公厅关于进一步优化支付服务 提升支付便利性的意见》要求&#xff0c;近日&#xff0c;中国人民银行、文化和旅游部、国家外汇管理局和国家文物局联合印发《关于进一步优化重点文旅场所支付服务 提升支付便利性的通知》…

【算法】二分算法题

个人主页 &#xff1a; zxctscl 如有转载请先通知 题目 1. 704. 二分查找1.1 分析1.2 代码 2. 34. 在排序数组中查找元素的第一个和最后一个位置2.1 分析2.2 代码 3. 35. 搜索插入位置3.1 分析3.2 代码 4. 852. 山脉数组的峰顶索引4.1 分析4.2 代码 5. 153. 寻找旋转排序数组中…