Element ui TimePicker 開始時間不得小於結束時間
阿新 • • 發佈:2020-12-21
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() } }, },