vue3 element-plus el-time-picker控制只显示时 分,并且控制可选的开始结束时间

发布于:2025-04-18 ⋅ 阅读:(18) ⋅ 点赞:(0)

 只显示时分

 控制只显示时分 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);
};


网站公告

今日签到

点亮在社区的每一天
去签到