实际上自定义这种时间选择器的disabled 都是有一个disabledDate设置的。如下列举的是iView的代码
html:
<FormItem label="日期" prop="date">
<Date-picker type="date" v-model="queryForm.date" placeholder="日期" :options="timeOptions"></Date-picker>
</FormItem>
js:
data(){
return{
timeOptions: {
disabledDate: (date) => {
let dateTime = new Date();
let year = dateTime.getFullYear();
let month = dateTime.getMonth();
let monthFirstDay = new Date(year, month, 1);
let newMonth = ++month;
let newYear = year;
if (newMonth >= 12) {
newMonth -= 12;
newYear++;
}
let monthNextDay = new Date(newYear, newMonth, 1);
let monthLastDay = new Date(
monthNextDay.getTime() - 24 * 60 * 60 * 1000
);
return ( date.valueOf() < new Date(monthFirstDay).getTime() || date.valueOf() > new Date(monthLastDay).getTime() );
},
},
}
}