Skip to content

DatePicker 日期选择器

用于选择或输入日期,支持日期、日期范围等模式。

基础用法

使用 v-model 绑定日期值,通过 type 属性切换选择模式。

快捷选项

通过 shortcuts 属性配置快捷选择项。

日期格式与禁用

通过 format 自定义显示格式,disabled 禁用选择器。

DatePicker API

Props

参数说明类型默认值
modelValue绑定值Date | [Date, Date] | string
type选择器类型date | daterangedate
placeholder占位文本string请选择日期
startPlaceholder范围选择时开始日期的占位文本string开始日期
endPlaceholder范围选择时结束日期的占位文本string结束日期
size选择器尺寸large | medium | smallmedium
disabled是否禁用booleanfalse
clearable是否可清空booleanfalse
format日期显示格式stringYYYY-MM-DD
shortcuts快捷选项列表DatePickerShortcut[]
disabledDate禁用日期判断函数(date: Date) => boolean

Events

事件名说明回调参数
update:modelValue绑定值更新时触发(value: Date | [Date, Date] | string)
change日期选择变化时触发(value: Date | [Date, Date])
focus获取焦点时触发(event: FocusEvent)
blur失去焦点时触发(event: FocusEvent)

DatePickerShortcut 类型

ts
interface DatePickerShortcut {
  text: string
  value: (() => Date | [Date, Date]) | Date | [Date, Date]
}

基于 MIT 许可发布