1.在 picker-options 属性中添加startTimed
<el-form-item prop="startTime"> <el-date-picker v-model="investigationForm.startTime" format="yyyy-MM-dd" type="date" placeholder="选择调查开始日期" :picker-options="startTimed" ></el-date-picker> </el-form-item> <el-form-item prop="endTime"> <el-date-picker v-model="investigationForm.endTime" format="yyyy-MM-dd" type="date" placeholder="选择调查结束日期" :picker-options="endTimed" ></el-date-picker> </el-form-item>
2.在data中定义 startTime
// 开始时间小于结束时间 且 不超过当天日期 startTimed: { disabledDate: (time) => { if (this.investigationForm.endTime) { return ( time.getTime() > new Date(this.investigationForm.endTime).getTime() ) } else { return time.getTime() > Date.now() } }, }, endTimed: { disabledDate: (time) => { if (this.investigationForm.startTime) { return ( time.getTime() > Date.now() || time.getTime() < new Date(this.investigationForm.startTime).getTime() ) } else { return time.getTime() > Date.now() } }, },