效果如下:
不多说,上代码:
:default-time="['00:00:00', new Date().toLocaleTimeString('chinese', { hour12: false })]"
设置当前默认结束时间new Date().toLocaleTimeString(‘chinese’, { hour12: false })
这里主要代码是
<el-form-item prop="carDate">
<el-date-picker
v-model="ruleForm.carDate"
:picker-options="pickerOptions"
type="datetimerange"
value-format="yyyy-MM-dd HH:mm:ss"
:default-time="['00:00:00', new Date().toLocaleTimeString('chinese', { hour12: false })]"
range-separator="至"
start-placeholder="开始时间"
end-placeholder="结束时间"
>
</el-date-picker>
</el-form-item>
pickerOptions: {
disabledDate: time => {
return time.getTime() > Date.now()
}
},
难点:默认选中当前时分秒