elementUI日期组件限制日期范围
限制区间30天:
pickerMinDate: '', pickerOptions: { onPick: ({ maxDate, minDate }) => { this.pickerMinDate = minDate.getTime() if (maxDate) this.pickerMinDate = '' }, disabledDate: (time) => { if (this.pickerMinDate !== '') { const one = 30 * 24 * 3600 * 1000 const minTime = this.pickerMinDate - one const maxTime = this.pickerMinDate + one return time.getTime() < minTime || time.getTime() > maxTime } } }
限制区间30天,不能大于今日:
pickerMinDate: '', pickerOptions: { onPick: ({ maxDate, minDate }) => { this.pickerMinDate = minDate.getTime() if (maxDate) this.pickerMinDate = '' }, disabledDate: (time) => { if (this.pickerMinDate !== '') { const one = 30 * 24 * 3600 * 1000 let minTime = this.pickerMinDate - one let maxTime = this.pickerMinDate + one if (maxTime > new Date()) maxTime = new Date() // 限制不能选择今天之后的日期 return time.getTime() < minTime || time.getTime() > maxTime } return time.getTime() > Date.now() } }
限制区间30天,不能小于今日:
pickerMinDate: '', pickerOptions: { onPick: ({ maxDate, minDate }) => { this.pickerMinDate = minDate.getTime() if (maxDate) this.pickerMinDate = '' }, disabledDate: (time) => { if (this.pickerMinDate !== '') { const one = 30 * 24 * 3600 * 1000 let minTime = this.pickerMinDate - one let maxTime = this.pickerMinDate + one if (minTime < new Date()) minTime = new Date() // 限制不能选择今天之前的日期 return time.getTime() < minTime || time.getTime() > maxTime } return time.getTime() < Date.now() - 8.64e7 // 加上 - 8.64e7 就可以选择今天 } }
选择今天及之前的日期:
pickerOptions: { disabledDate: (time) => { return time.getTime() > Date.now() } }
选择今天之前的日期:
pickerOptions: { disabledDate: (time) => { return time.getTime() > Date.now() - 8.64e7 } }
选择今天及之后的日期:
pickerOptions: { disabledDate: (time) => { return time.getTime() < Date.now() - 8.64e7 } }
选择今天之后的日期:
pickerOptions: { disabledDate: (time) => { return time.getTime() < Date.now() } }
结束日期不能大于开始日期: