<el-date-picker :picker-options="pickerOptions"></el-date-picker>
data(){
return{
pickerOptions: {
onPick: ({
maxDate,
minDate
}) => {
this.choiceDate = minDate.getTime();
if (maxDate) {
this.choiceDate = '';
}
},
disabledDate: (time) => {
let choiceDateTime = new Date(this.choiceDate).getTime();
var minTime = new Date(choiceDateTime).setMonth(new Date(choiceDateTime).getMonth() - 3);
var maxTime = new Date(choiceDateTime).setMonth(new Date(choiceDateTime).getMonth() + 3);
var min = minTime;
var newDate = new Date(new Date().toLocaleDateString()).getTime() + 3600 * 1000 * 24 - 1;
var max = maxTime > newDate ? newDate : maxTime;
if (this.choiceDate) {
return time.getTime() < min || time.getTime() > max;
}
return Date.now() - time.getTime() > 3600 * 1000 * 24 * 366 * 3 || Date.now() < time.getTime();
},
}
}