Element UI DateTimePicker 日期时间选择器限制最长选择范围为一年
可以通过设置 DateTimePicker 的 type 属性为 'daterange',然后设置 picker-options 属性中的 ranges 属性,来限制日期时间选择器的最长时间范围为一年。具体代码如下:
<el-date-picker
v-model='dateRange'
type='daterange'
:picker-options='pickerOptions'>
</el-date-picker>
...
data() {
return {
dateRange: [],
pickerOptions: {
ranges: {
'一年内': [moment(), moment().add(1, 'year')]
}
}
}
}
其中,pickerOptions 中的 ranges 属性设置了一个名为 '一年内' 的时间范围,起始时间为当前时间,结束时间为当前时间加上一年。这样就限制了日期时间选择器的最长时间范围为一年。
原文地址: https://www.cveoy.top/t/topic/nm5s 著作权归作者所有。请勿转载和采集!