Skip to content

TimePicker 时间选择

用于选择时间,支持时分秒、时分等模式。

基础用法

vue
<template>
  <button @click="show = true">选择时间</button>
  <text>{{ value }}</text>

  <dr-time-picker
    v-model:show="show"
    title="选择时间"
    @confirm="onConfirm"
  />
</template>

<script setup>
import { ref } from 'vue'

const show = ref(false)
const value = ref('')

const onConfirm = (e) => {
  value.value = e.value // 14:30:00
}
</script>

时分模式

设置 mode="hour-minute" 只选择时分。

vue
<dr-time-picker
  v-model:show="show"
  mode="hour-minute"
  title="选择时间"
  @confirm="onConfirm"
/>

限制时间范围

通过 min-timemax-time 限制可选时间范围。

vue
<dr-time-picker
  v-model:show="show"
  min-time="09:00:00"
  max-time="18:00:00"
  title="选择工作时间"
/>

默认时间

通过 v-model 设置默认选中的时间。

vue
<dr-time-picker
  v-model:show="show"
  v-model="time"
  title="选择时间"
/>

<script setup>
const time = ref('12:00:00')
</script>

API

Props

参数说明类型默认值
v-model:show是否显示booleanfalse
v-model当前选中时间string''
mode模式:time hour-minutestringtime
min-time最小可选时间string00:00:00
max-time最大可选时间string23:59:59
title标题string选择时间
show-toolbar是否显示工具栏booleantrue
confirm-text确认按钮文字string确定
cancel-text取消按钮文字string取消
hour-suffix小时单位string
minute-suffix分钟单位string
second-suffix秒单位string
mask-closable点击遮罩是否关闭booleantrue
z-index层级number5000

Events

事件名说明回调参数
confirm点击确认时触发{ value: string }
cancel点击取消时触发-
change选择变化时触发{ value: string }
close关闭时触发-

基于 MIT 许可发布