使用
<el-date-picker v-model="form.years" type="month" placeholder="请选择" style="width: 100%"
:picker-options="pickerYearsOptions"/>
<el-date-picker clearable v-model="form.buildDate" type="daterange" :picker-options="pickerOptions"
range-separator="~" start-placeholder="开始日期" style="width: 100%"
end-placeholder="结束日期"/>
js:
data() {
return {
// 设置不能选则当月之前的时间
pickerYearsOptions: {
disabledDate(time) {
if (time.getFullYear() < new Date().getFullYear()) {
return time.getMonth() < 12;
}
if (time.getFullYear() == new Date().getFullYear()) {
return time.getMonth() < new Date().getMonth();
}
},
},
// 设置不能选则当天之前的时间
pickerOptions: {
disabledDate(time) {
return time.getTime() < Date.now() - 8.64e7;
},
},
};
},