只显示时分
控制只显示时分 HH:mm
控制只显示时分秒 HH:mm:ss
全部代码:
<template>
<el-time-picker
style="width: 220px !important;"
v-model="timeValue"
format="HH:mm"
value-format="HH:mm"
/>
</template>
<script setup>
import {ref} from 'vue';
const timeValue = ref('8:00');
</script>
<style scoped>
.el-time-spinner__wrapper:last-child {
display: none !important;
}
</style>
效果:
时分 HH:mm /时分秒 HH:mm:ss
控制可选开始结束日期
:disabled-hours="disabledHours" :disabled-minutes="disabledMinutes"
全部代码
<template>
<el-time-picker
style="width: 220px !important;"
v-model="timeValue"
format="HH:mm:"
value-format="HH:mm"
:disabled-hours="disabledHours"
:disabled-minutes="disabledMinutes"
/>
</template>
<script setup>
import {ref} from 'vue';
const timeValue = ref('8:00');
const disabledHours = () => {
return Array.from({length: 24}, (_, h) => h)
.filter(h => h < 8 || h > 16);
};
const disabledMinutes = (selectedHour) => {
if (selectedHour === 16) return [];
return [];
};
</script>
<style scoped>
.el-time-spinner__wrapper:last-child {
display: none !important;
}
</style>
效果:
8点之前16点之后的不可以选择:
const disabledHours = () => { return Array.from({length: 24}, (_, h) => h) .filter(h => h < 8 || h > 16); };
8点之后16点之前的不可以选择:
const disabledHours = () => { return Array.from({length: 24}, (_, h) => h) .filter(h => h > 8 && h < 16); };