Skip to content

时间选择器

时间选择器用于选择时间。

基础用法

ts
const config = {
  type: 'time',
  formItem: {
    label: '上课时间'
  },
  time: {
    format: 'HH:mm:ss',
    placeholder: '请选择时间',
    hourStep: 1,
    minuteStep: 5,
    secondStep: 10
  }
}

API

属性说明类型默认值
allowClear是否展示清除按钮booleantrue
autofocus自动获取焦点booleanfalse
bordered是否有边框booleantrue
clearIcon自定义的清除图标VNode-
clearText清除按钮的提示文案stringclear
disabled禁用全部操作booleanfalse
disabledTime不可选择的时间DisabledTime-
format展示的时间格式stringHH:mm:ss
getPopupContainer定义浮层的容器,默认为 body 上新建 divfunction(trigger)-
hideDisabledOptions隐藏禁止选择的选项booleanfalse
hourStep小时选项间隔number1
inputReadOnly设置输入框为只读(避免在移动设备上打开虚拟键盘)booleanfalse
minuteStep分钟选项间隔number1
open面板是否打开booleanfalse
placeholder没有值的时候显示的内容string请选择时间
placement选择框弹出的位置bottomLeft bottomRight topLeft topRightbottomLeft
popupClassName弹出层类名string-
popupStyle弹出层样式对象object-
renderExtraFooter选择框底部显示自定义的内容VNode-
secondStep秒选项间隔number1
showNow面板是否显示“此刻”按钮boolean-
status设置校验状态'error''warning'
suffixIcon自定义的选择框后缀图标VNode-
use12Hours使用 12 小时制,为 true 时 format 默认为 h:mm:ss abooleanfalse
value当前时间dayjs-
valueFormat可选,绑定值的格式,对 value、defaultValue 起作用。不指定则绑定值为 dayjs 对象string-

更多属性请参考 Ant Design Vue TimePicker

示例

vue
<script setup lang="ts">
const columns = [
  {
    title: '上课时间',
    dataIndex: 'classTime',
    edit: {
      type: 'time',
      formItem: {
        required: true
      },
      time: {
        format: 'HH:mm',
        placeholder: '请选择上课时间',
        hourStep: 1,
        minuteStep: 5,
      }
    }
  },
  {
    title: '营业时间',
    dataIndex: 'businessHours',
    edit: {
      type: 'time',
      formItem: {
        label: '营业时间'
      },
      time: {
        format: 'h:mm a',
        use12Hours: true,
        placeholder: '请选择营业时间',
        hourStep: 1,
        minuteStep: 30
      }
    }
  }
]
</script>

根据 Apache-2.0 许可发布。