el-date-picker 只能选择后三个工作日并且遇到周末要顺延
时间: 2023-05-12 22:05:56 浏览: 105
您可以使用 moment.js 库来计算日期并过滤掉周末,然后将结果传递给 el-date-picker 组件。以下是一个示例代码片段:
```
<template>
<el-date-picker
v-model="selectedDate"
:disabled-date="disabledDate"
:picker-options="pickerOptions"
></el-date-picker>
</template>
<script>
import moment from 'moment';
export default {
data() {
return {
selectedDate: null,
pickerOptions: {
disabledDate: (time) => {
const currentDate = moment();
const selectedDate = moment(time);
const diff = selectedDate.diff(currentDate, 'days');
const isWeekend = selectedDate.day() === 6 || selectedDate.day() === 0;
return diff < 1 || diff > 3 || isWeekend;
},
},
};
},
methods: {
disabledDate(time) {
const currentDate = moment();
const selectedDate = moment(time);
const diff = selectedDate.diff(currentDate, 'days');
const isWeekend = selectedDate.day() === 6 || selectedDate.day() === 0;
return diff < 1 || diff > 3 || isWeekend;
},
},
};
</script>
```
在这个示例中,我们使用 moment.js 库来计算当前日期和所选日期之间的天数差异,并检查所选日期是否是周末。如果日期不在后三个工作日范围内或者是周末,我们就将其禁用。我们还将 `disabledDate` 方法传递给 `picker-options` 属性,以便在日期选择器中禁用无效日期。
阅读全文