当前位置: 首页 > news >正文

elementUI中2个日期组件实现开始时间、结束时间(禁用日期面板、控制开始时间不能超过结束时间的时分秒)实现方案

没有使用selectableRange 禁用时分秒,是因为他会禁止每天的时分秒。 我们需要解决的是当开始时间、结束时间是同一天时, 开始时间不能超过结束时间。 如果直接清空,用户体验不好。所以用watch监听赋值,当前操作谁,它不满足条件,就改变它本身。

<el-col :span="8"><el-form-item label="开始时间" prop="startDate" :rules="globalRules.requiredBlurOrChange"><el-date-pickerv-model="formNew.startDate"type="datetime"format="yyyy-MM-dd HH:mm:ss"value-format="yyyy-MM-dd HH:mm:ss":picker-options="{...editStartOptions}"placeholder="选择日期"@change="changeDate"></el-date-picker></el-form-item></el-col><el-col :span="8"><el-form-item label="完成时间" prop="endDate" :rules="globalRules.requiredBlurOrChange"><el-date-pickerv-model="formNew.endDate"type="datetime"format="yyyy-MM-dd HH:mm:ss"value-format="yyyy-MM-dd HH:mm:ss":picker-options="{...editStopOptions}"placeholder="选择日期"@change="changeDate"></el-date-picker></el-form-item></el-col>data() {return {editStartOptions: {disabledDate: time => {if (!this.formNew.endDate) {return time.getTime() < new Date(1970 - 1 - 1).getTime();   //禁止选择1970年以前的日期} else {return time.getTime() > new Date(this.formNew.endDate);}},},editStopOptions: {disabledDate: time => {//开始时间可以和结束时间相同增加let startDate= new Date(this.formNew.startDate);startDate.setDate(startDate.getDate() - 1);return (time.getTime() < startDate || time.getTime() < new Date(1970 - 1 - 1).getTime()    //禁止选择1970年以前的日期);},},}
}watch: {'formNew.startDate': {handler(newVal) {if (newVal && this.formNew.endDate && new Date(newVal).getTime() > new Date(this.formNew.endDate).getTime()) {this.formNew.startDate = this.formNew.endDateconsole.log(newVal, 'newVal')}}},'formNew.endDate': {handler(newVal) {if (newVal && this.formNew.startDate && new Date(newVal).getTime() < new Date(this.formNew.startDate).getTime()) {// this.formNew.startDate = newVal;this.formNew.endDate = this.formNew.startDate}}},},
http://www.lryc.cn/news/482593.html

相关文章:

  • Oracle 聚集因子factor clustering
  • 【大数据学习 | kafka高级部分】kafka的快速读写
  • 云技术基础
  • 字节序(Byte Order)
  • 融云:社交泛娱乐出海机会尚存,跨境电商异军突起
  • django博客项目实现站内搜索功能
  • 蓝桥杯c++算法学习【1】之枚举与模拟(卡片、回文日期、赢球票、既约分数:::非常典型的比刷例题!!!)
  • Android 延时操作的常用方法
  • AI驱动的轻量级笔记应用Blinko
  • 一文搞懂 UML 类图
  • Zabbix 7 最新版本安装 Rocky Linux 8
  • 使用HTML、CSS和JavaScript创建动态雪人和雪花效果
  • redis bind 127.0.0.1和bind 10.34.56.78的区别
  • 基于点云的 3D 目标检测模型 PointPillars 部署 tensorRT
  • centos查看硬盘资源使用情况命令大全
  • Solon MVC 的 @Mapping 用法说明
  • uni-app表单⑪
  • PyQt5 加载UI界面与资源文件
  • 【MySQL】数据库知识突破:数据类型全解析与详解
  • 使用Golang实现开发中常用的【实例设计模式】
  • 【Java学习】电脑基础操作和编程环境配置
  • AVL树解析
  • 栈和队列(Java)
  • C#设计原则
  • easyfs 简易文件系统
  • 【架构论文-1】面向服务架构(SOA)
  • 刚刚!更新宁德时代社招Verify测评语言理解数字推理SHL题库、网盘资料、高分答案
  • C++笔记---智能指针
  • CentOS 7系统中更改YUM源为阿里云的镜像源
  • Python酷库之旅-第三方库Pandas(206)