<el-date-picker v-model="due_date" type="date" size="small" value-format="yyyy-MM-dd" :picker-options="pickerOptions0" placeholder="pick date"> </el-date-picker>
1.今日以后
pickerOptions0: { disabledDate(time) { return time.getTime() < Date.now() - 8.64e7 } }
2.前一个月
pickerOptions0: { disabledDate(time) { const lastMonthTime = new Date().setMonth(new Date().getMonth() - 1) return time.getTime() > Date.now() || time < lastMonthTime } }
3.后一个月
pickerOptions0: { disabledDate(time) { const lastMonthTime = new Date().setMonth(new Date().getMonth() + 1) return time.getTime() < Date.now() || time > lastMonthTime } }
daterange范围前后一个月
<el-date-picker v-model="promotionDateRange" type="daterange" :picker-options="pickerOptions" range-separator="至" start-placeholder="开始日期" end-placeholder="结束日期"> </el-date-picker>
data() { return { promotionDateRange:[], selectDate: '', // 日期时间范围在一个月以内 pickerOptions: { onPick: ({ maxDate, minDate }) => { this.selectDate = minDate.getTime() if (maxDate) { this.selectDate = '' } }, disabledDate: (time) => { if (this.selectDate !== '') { const one = 30 * 24 * 3600 * 1000 const minTime = this.selectDate - one const maxTime = this.selectDate + one return time.getTime() < minTime || time.getTime() > maxTime } } }, } }