el-date-picker限制范围一天以内
时间: 2023-10-08 17:09:08 浏览: 132
要限制el-date-picker选择范围为一天以内,可以使用pickerOptions的disabledDate属性来实现。具体的实现方法如下所示:
```javascript
pickerOptions: {
disabledDate(time) {
const today = new Date();
today.setHours(0, 0, 0, 0);
const tomorrow = new Date();
tomorrow.setDate(tomorrow.getDate() + 1);
tomorrow.setHours(0, 0, 0, 0);
return time.getTime() < today.getTime() || time.getTime() > tomorrow.getTime();
}
}
```
在pickerOptions中的disabledDate函数中,我们可以通过比较时间来限制选择的范围。首先,我们获取到当前时间的日期,并将时、分、秒、毫秒都设为0,得到today。然后,我们创建一个新的日期对象tomorrow,将其设置为明天的日期,并同样将时、分、秒、毫秒都设为0。
接下来,我们比较选择的时间是否早于today或晚于tomorrow,如果是,则禁用该时间。这样就实现了限制范围为一天以内的效果。
希望对你有帮助!<span class="em">1</span><span class="em">2</span><span class="em">3</span>
#### 引用[.reference_title]
- *1* [el-date-picker日期的限制](https://blog.csdn.net/qq_45838276/article/details/125489197)[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^v93^chatsearchT3_1"}}] [.reference_item style="max-width: 50%"]
- *2* *3* [el-date-picker日期选择限制选择范围](https://blog.csdn.net/m0_63026408/article/details/131100520)[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^v93^chatsearchT3_1"}}] [.reference_item style="max-width: 50%"]
[ .reference_list ]
阅读全文