How to set the maximum date span for Element UI's date-time-picker to select only one month

Use the date range control of Element in

vue, the one of < date-time-picker type= "datetimerange" >.
there are currently two restrictions: the start and end dates cannot be more than one month. The date choice is no more than today.

it seems that only one time can be passed in date-options, how to control it here.

dateValue:[new Date().setTime(new Date().getTime()-3600 * 1000 * 24),new Date()],
dateOpt: {
    disabledDate:(time)=>{
        return time.getTime() > Date.now() - 8.64e6;
    }
},

clipboard.png

May.12,2022

you can use the change event to listen for changes in values, so that you can judge whether it is more than one month in the method. If it is more than one month, trigger a warning to the form validator


pickerOptions: {
    disabledDate(time) {
        const lastMonthTime = new Date().setMonth(new Date().getMonth() - 1)
        return time.getTime() > Date.now() || time < lastMonthTime
    }
}
.
Menu