Vue 判断开始时间不能大于结束时间
原文链接:https://blog.csdn.net/lzfengquan/article/details/119993515
<template>
<div>
<el-form ref="form" :model="form" label-width="80px">
<el-form-item label="活动时间">
<el-col :span="11">
<el-date-picker
type="date"
value-format="yyyy-MM-dd"
placeholder="选择日期"
v-model="form.startDate"
:picker-options="pickerOptions"
style="width: 100%;"
@change="changeData(true)"
></el-date-picker>
</el-col>
<el-col class="line" :span="2">-</el-col>
<el-col :span="11">
<el-date-picker
type="date"
value-format="yyyy-MM-dd"
placeholder="选择日期"
v-model="form.endDate"
:picker-options="pickerOptions"
style="width: 100%;"
@change="changeData(false)"
></el-date-picker>
</el-col>
</el-form-item>
</el-form>
</div>
</template>
<script>
export default {
data() {
return {
form: {
startDate: "", // 开始时间
endDate: "" // 结束时间
},
pickerOptions: {
disableDate: time => {
return time.getTime() > Date.now();
}
}
};
},
methods: {
changeData(flag) {
if (flag) {
if (this.form.endDate) {
if (this.form.startDate > this.form.endDate) {
this.form.startDate = null;
this.$message.error("开始时间不能大于结束时间!");
}
}
} else {
if (this.form.startDate) {
if (this.form.startDate > this.form.endDate) {
this.form.endDate = null;
this.$message.error("结束时间不能小于开始时间!");
}
}
}
}
}
};
</script>
<style lang="scss" scoped></style>
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 全程不用写代码,我用AI程序员写了一个飞机大战
· DeepSeek 开源周回顾「GitHub 热点速览」
· 记一次.NET内存居高不下排查解决与启示
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· .NET10 - 预览版1新功能体验(一)
2022-09-08 java将图片转成(BASE64)
2020-09-08 SpringCloudStream集成kafka