el-date-picker 禁用:
el-date-picker type属性"datetime" ,想在一个框 ,可以限制日期+时间段的禁用如下:
<el-date-picker
v-model="postData.createDate"
type="datetime"
value-format="yyyy-MM-dd HH:mm:ss"
:picker-options="pickerOptions"
placeholder="选择日期">
</el-date-picker>
const time = '2022-12-10 10:10:10';
const time2 = '2022-12-12 12:12:12';
const time_date1 = time.split(' ')[0];
const _start = time.split(' ')[1];
const _end = time2.split(' ')[1];
const _selectableRange = `${_start} - ${_end}`;
pickerOptions: {
// 设置可选的时间范围
selectableRange: _selectableRange,
disabledDate(date) {
// 小于开始时间的禁用
const disabledBefore = new Date(time_date1 + ' :00:00:00');
return new Date(date).getTime() < disabledBefore.getTime()
}
},
如果有更好的方法可以评论留言;