el-date-picker限制范围14天
时间: 2023-08-16 21:09:52 浏览: 82
根据提供的引用内容,可以使用以下代码来限制el-date-picker的选择范围为14天:
```html
<el-date-picker
v-model="dateRange"
type="daterange"
value-format="yyyy-MM-dd"
placeholder="请选择日期"
range-separator="至"
start-placeholder="开始日期"
end-placeholder="结束日期"
:picker-options="setDateRange"
></el-date-picker>
```
```javascript
data() {
return {
dateRange: \[\],
setDateRange: {
disabledDate: time => {
const fourteenDays = 14 * 24 * 3600 * 1000;
const minTime = Date.now() - fourteenDays;
const maxTime = Date.now() + fourteenDays;
return time.getTime() < minTime || time.getTime() > maxTime;
}
}
}
}
```
这段代码中,我们使用了`disabledDate`属性来限制可选择的日期范围。通过计算出14天前和14天后的时间戳,我们可以禁用早于14天前和晚于14天后的日期。这样就实现了限制范围为14天的功能。\[1\]
#### 引用[.reference_title]
- *1* *3* [el-date-picker限制日期选择范围](https://blog.csdn.net/qq_45039940/article/details/122103164)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^koosearch_v1,239^v3^insert_chatgpt"}} ] [.reference_item]
- *2* [el-date-picker 限制选择日期在一个月范围内](https://blog.csdn.net/HH18700418030/article/details/127789981)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^koosearch_v1,239^v3^insert_chatgpt"}} ] [.reference_item]
[ .reference_list ]
阅读全文