element ui里的日期选择器设置只能选择当前日期之后的两天,且排除周末,日期自动递增...
时间: 2024-02-21 21:57:52 浏览: 75
基于freeRTOS和STM32F103x的手机远程控制浴室温度系统设计源码
好的,对于你的问题,可以通过如下代码实现:
```html
<el-date-picker
v-model="date"
:picker-options="pickerOptions"
:disabled-date="disabledDate"
></el-date-picker>
```
```javascript
data() {
return {
date: null,
pickerOptions: {
disabledDate: (time) => {
const today = new Date();
const tomorrow = new Date(today.getTime() + 24 * 60 * 60 * 1000);
const afterTomorrow = new Date(today.getTime() + 2 * 24 * 60 * 60 * 1000);
const day = time.getDay();
return time.getTime() < tomorrow || time.getTime() > afterTomorrow || day === 6 || day === 0;
}
}
};
},
methods: {
disabledDate(time) {
const today = new Date();
const tomorrow = new Date(today.getTime() + 24 * 60 * 60 * 1000);
const afterTomorrow = new Date(today.getTime() + 2 * 24 * 60 * 60 * 1000);
const day = time.getDay();
return time.getTime() < tomorrow || time.getTime() > afterTomorrow || day === 6 || day === 0;
}
}
```
其中,`pickerOptions` 中的 `disabledDate` 函数用于禁止选择特定日期,可以通过设置 `time` 参数来判断当前日期是否符合条件。具体地,如果当前日期小于明天或者大于后天,或者是周六或周日,则禁止选择。而 `disabledDate` 方法则是用于在组件初始化时也对日期进行过滤。
阅读全文