<el-form-item label="颁发日期" :rules="[{ required: true, message: '颁发日期不能为空' }]"> <el-date-picker v-model="formData.promulgateDate" value-format="yyyy-MM-dd" type="year" placeholder="选择年" :style="{ width: '33%' }" > </el-date-picker> </el-form-item> <el-form-item label="实施日期" :rules="[{ required: true, message: '实施日期不能为空' }]"> <el-date-picker v-model="formData.execDate" value-format="yyyy-MM-dd" type="year" placeholder="选择年" :style="{ width: '33%' }" :picker-options="expireTimeOption" > </el-date-picker> </el-form-item> <el-form-item label="失效日期" :rules="[{ required: true, message: '失效日期不能为空' }, { validator: (rule, value, callback) => checkExpiryDate(rule, value, callback, formData.promulgateDate), trigger: 'blur' }]"> <el-date-picker v-model="formData.expiryDate" value-format="yyyy-MM-dd" type="year" placeholder="选择年" :style="{ width: '33%' }" :picker-options="expiryDateOption"> </el-date-picker> </el-form-item> expiryDateOption: { // disabledDate: (time) => { // return time.getTime()< new Date(this.formData.promulgateDate).getTime() // } disabledDate: (time) => { if (!this.formData.execDate) { // 如果 execDate 为空,expiryDate<promulgateDate return time.getTime() < new Date(this.formData.promulgateDate).getTime() } else if (time.getTime() < new Date(this.formData.execDate).getTime()) { return this.formData.execDate = null } else if (time.getTime() > new Date(this.formData.promulgateDate).getTime()) { return this.formData.expiryDate = null } else { return time.getTime() < new Date(this.formData.promulgateDate).getTime() } },优化下这个方法

时间: 2024-03-11 19:43:25 浏览: 11
这段代码的主要作用是限制失效日期的选择范围,使其不能早于颁发日期或实施日期。以下是我给出的优化建议: 1. 将失效日期选择器的限制方法单独提出来,方便复用和测试。 2. 将失效日期选择器的限制方法拆分为两个部分,分别处理失效日期早于实施日期和晚于颁发日期的情况。 3. 增加对失效日期和实施日期的非空判断,避免空指针异常。 4. 修改失效日期选择器的限制方法的命名,使其更加准确和易懂。 优化后的代码如下: ``` function disableExpiryDate(time) { if (!this.formData.execDate) { // 如果 execDate 为空,expiryDate<promulgateDate return time.getTime() < new Date(this.formData.promulgateDate).getTime(); } else if (time.getTime() < new Date(this.formData.execDate).getTime()) { // 处理失效日期早于实施日期的情况 return true; } else if (time.getTime() > new Date(this.formData.promulgateDate).getTime()) { // 处理失效日期晚于颁发日期的情况 return true; } else { return false; } } // 在模板中使用 <el-form-item label="失效日期" :rules="[{ required: true, message: '失效日期不能为空' }, { validator: (rule, value, callback) => checkExpiryDate(rule, value, callback, formData.promulgateDate), trigger: 'blur' }]"> <el-date-picker v-model="formData.expiryDate" value-format="yyyy-MM-dd" type="year" placeholder="选择年" :style="{ width: '33%' }" :picker-options="expiryDatePickerOptions"></el-date-picker> </el-form-item> // 在组件中定义 data() { return { expiryDatePickerOptions: { disabledDate: disableExpiryDate.bind(this) } }; } ```

相关推荐

<el-form-item label="联系人" prop="contactsList"> <el-button type="primary" link :disabled="dialogType === 'check'" @click="handleContactsInfo">添加</el-button> <el-table :data="infoForm.contactsList" border stripe size="small"> <el-table-column label="姓名" prop="ContactsName"> <template #default="{ row }"> <el-input :disabled="dialogType === 'check'" v-model.trim="row.ContactsName" maxlength="20" placeholder="请填写姓名" show-word-limit ></el-input> </template> </el-table-column> <el-table-column label="部门" prop="ContactsDepartment"> <template #default="{ row }"> <el-input :disabled="dialogType === 'check'" v-model.trim="row.ContactsDepartment" maxlength="20" show-word-limit placeholder="请填写部门" ></el-input> </template> </el-table-column> <el-table-column label="职务" prop="ContactsDuty"> <template #default="{ row }"> <el-input :disabled="dialogType === 'check'" v-model.trim="row.ContactsDuty" maxlength="20" show-word-limit placeholder="请填写职务" ></el-input> </template> </el-table-column> <el-table-column label="联系方式" prop="ContactNumber"> <template #default="{ row }"> <el-input :disabled="dialogType === 'check'" v-model.trim="row.ContactNumber" maxlength="50" show-word-limit placeholder="请填写联系方式" ></el-input> </template> </el-table-column> <el-table-column label="操作" width="56px"> <template #default="{ $index }"> <el-button type="primary" link size="small" :disabled="dialogType === 'check'" @click="handleRemove($index)" > 删除 </el-button> </template> </el-table-column> </el-table> </el-form-item> 该表单初始就有一个,且至少保留一个,对表单内姓名一栏进行必填校验

<template> <el-form ref="loginForm" :model="loginForm" :rules="loginRules" label-position="top"> <el-form-item label="用户名" prop="username"> <el-input v-model="loginForm.username"></el-input> </el-form-item> <el-form-item label="密码" prop="password"> <el-input type="password" v-model="loginForm.password"></el-input> </el-form-item> <el-form-item> <el-button type="primary" @click="login">登录</el-button> </el-form-item> </el-form> </template> <script> import { login } from '@/api'; export default { name: 'LoginPage', data() { return { loginForm: { username: '', password: '' }, loginRules: { username: [ { required: true, message: '请输入用户名', trigger: 'blur' } ], password: [ { required: true, message: '请输入密码', trigger: 'blur' } ] } }; }, methods: { login() { this.$refs.loginForm.validate(valid => { if (valid) { // 登录逻辑,可以发送请求到后端进行验证 const { username, password } = this.loginForm; // 修改这里 console.log(username, password); login(username, password) .then(response => { // 登录成功,处理响应 console.log(response.data); // 进行其他操作,例如跳转到其他页面 this.$router.push('/'); }) .catch(error => { // 登录失败,处理错误 console.error(error); // 进行错误提示或其他操作 }); console.log('登录成功'); // 登录成功后跳转到首页 } else { console.log('表单验证失败'); } }); } } }; </script> <style scoped> .login-container { display: flex; justify-content: center; align-items: center; height: 100vh; } </style> 密码验证成功后路由没有正常跳转到首页

</head> <body> <el-form id="login" class="demo-ruleForm" :rules="rules" :model="ruleForm"> <el-form-item label="用户名" prop="username"> <el-input v-model="ruleForm.username"></el-input> </el-form-item> <el-form-item label="密码" prop="password"> <el-input v-model="ruleForm.password" type="password"></el-input> </el-form-item> <el-form-item> <el-button type="primary" @click="loginHandler()">登录</el-button> </el-form-item> </el-form> </body> <script> new Vue({ el: "#login", data() { return { ruleForm:{ username: "", password: "", }, rules: { username: [{ required: true, message: '请输入用户名', trigger: 'blur' }, { min: 2, max: 10, message: '长度在 2 到 10 个字符', trigger: 'blur' } ], password: [{ required: true, message: '请输入密码', trigger: 'blur' }, { min: 2, max: 10, message: '长度在 2 到 10 个字符', trigger: 'blur' } ] } } }, methods: { loginHandler() { axios.post("http://localhost:9000/mvc_web/login?username="+this.ruleForm.username + "&password=" + this.ruleForm.password).then(function(response) { if(response.status==200){ if(response.data.id!=0){ //将数据保存在本地缓存中 /* window.localStorage.setItem("user",JSON.stringify(response.data)) */ //将数据保存到服务器中 sessionStorage.setItem("user",JSON.stringify(response.data)) window.location.href="home.html"} else{ console.log("账户或密码错误,请重新输入") } } }) .catch(function(error) { console.log(error) }) } } }) </script> </html> //Home.html <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title></title> <script src="js/vue.js"></script> </head> <body> 欢迎{{user.username}}登录 </body> <script> new Vue({ el:"#home", data:{ user:JSON.parse(sessionStorage.getItem("user")) } }) </script> </html>解释每行代码

最新推荐

recommend-type

埃森哲制药企业数字化转型项目顶层规划方案glq.pptx

埃森哲制药企业数字化转型项目顶层规划方案glq.pptx
recommend-type

华为OD机试D卷 - 机场航班调度程序 - 免费看解析和代码.html

私信博主免费获取真题解析以及代码
recommend-type

基于FPGA读取设计的心电图代码源码+全部资料齐全.zip

【资源说明】 基于FPGA读取设计的心电图代码源码+全部资料齐全.zip基于FPGA读取设计的心电图代码源码+全部资料齐全.zip 【备注】 1、该项目是高分课程设计项目源码,已获导师指导认可通过,答辩评审分达到95分 2、该资源内项目代码都经过mac/window10/11/linux测试运行成功,功能ok的情况下才上传的,请放心下载使用! 3、本项目适合计算机相关专业(如软件工程、计科、人工智能、通信工程、自动化、电子信息等)的在校学生、老师或者企业员工下载使用,也可作为课程设计、作业、项目初期立项演示等,当然也适合小白学习进阶。 4、如果基础还行,可以在此代码基础上进行修改,以实现其他功能,也可直接用于课设、作业等。 欢迎下载,沟通交流,互相学习,共同进步!
recommend-type

zigbee-cluster-library-specification

最新的zigbee-cluster-library-specification说明文档。
recommend-type

管理建模和仿真的文件

管理Boualem Benatallah引用此版本:布阿利姆·贝纳塔拉。管理建模和仿真。约瑟夫-傅立叶大学-格勒诺布尔第一大学,1996年。法语。NNT:电话:00345357HAL ID:电话:00345357https://theses.hal.science/tel-003453572008年12月9日提交HAL是一个多学科的开放存取档案馆,用于存放和传播科学研究论文,无论它们是否被公开。论文可以来自法国或国外的教学和研究机构,也可以来自公共或私人研究中心。L’archive ouverte pluridisciplinaire
recommend-type

实现实时数据湖架构:Kafka与Hive集成

![实现实时数据湖架构:Kafka与Hive集成](https://img-blog.csdnimg.cn/img_convert/10eb2e6972b3b6086286fc64c0b3ee41.jpeg) # 1. 实时数据湖架构概述** 实时数据湖是一种现代数据管理架构,它允许企业以低延迟的方式收集、存储和处理大量数据。与传统数据仓库不同,实时数据湖不依赖于预先定义的模式,而是采用灵活的架构,可以处理各种数据类型和格式。这种架构为企业提供了以下优势: - **实时洞察:**实时数据湖允许企业访问最新的数据,从而做出更明智的决策。 - **数据民主化:**实时数据湖使各种利益相关者都可
recommend-type

用 Python 画一个可以动的爱心

好的,我可以帮助您使用Python来绘制一个动态的爱心。您可以使用turtle库来实现。以下是实现代码: ```python import turtle import math # 设置画布和画笔 canvas = turtle.Screen() canvas.bgcolor("black") pencil = turtle.Turtle() pencil.speed(0) pencil.color("red", "pink") pencil.pensize(3) # 定义爱心函数 def draw_love(heart_size, x_offset=0, y_offset=0):
recommend-type

JSBSim Reference Manual

JSBSim参考手册,其中包含JSBSim简介,JSBSim配置文件xml的编写语法,编程手册以及一些应用实例等。其中有部分内容还没有写完,估计有生之年很难看到完整版了,但是内容还是很有参考价值的。
recommend-type

"互动学习:行动中的多样性与论文攻读经历"

多样性她- 事实上SCI NCES你的时间表ECOLEDO C Tora SC和NCESPOUR l’Ingén学习互动,互动学习以行动为中心的强化学习学会互动,互动学习,以行动为中心的强化学习计算机科学博士论文于2021年9月28日在Villeneuve d'Asq公开支持马修·瑟林评审团主席法布里斯·勒菲弗尔阿维尼翁大学教授论文指导奥利维尔·皮耶昆谷歌研究教授:智囊团论文联合主任菲利普·普雷教授,大学。里尔/CRISTAL/因里亚报告员奥利维耶·西格德索邦大学报告员卢多维奇·德诺耶教授,Facebook /索邦大学审查员越南圣迈IMT Atlantic高级讲师邀请弗洛里安·斯特鲁布博士,Deepmind对于那些及时看到自己错误的人...3谢谢你首先,我要感谢我的两位博士生导师Olivier和Philippe。奥利维尔,"站在巨人的肩膀上"这句话对你来说完全有意义了。从科学上讲,你知道在这篇论文的(许多)错误中,你是我可以依
recommend-type

实现实时监控告警系统:Kafka与Grafana整合

![实现实时监控告警系统:Kafka与Grafana整合](https://imgconvert.csdnimg.cn/aHR0cHM6Ly9tbWJpei5xcGljLmNuL21tYml6X2pwZy9BVldpY3ladXVDbEZpY1pLWmw2bUVaWXFUcEdLT1VDdkxRSmQxZXB5R1lxaWNlUjA2c0hFek5Qc3FyRktudFF1VDMxQVl3QTRXV2lhSWFRMEFRc0I1cW1ZOGcvNjQw?x-oss-process=image/format,png) # 1.1 Kafka集群架构 Kafka集群由多个称为代理的服务器组成,这