Datetime Picker 日期时间选择器
在同一选择器中选择日期与时间。
日期与时间
将 type 设为 datetime 即可同时选择日期与时间;快捷项用法与日期选择器相同。
Default
With shortcuts
With default time
日期时间格式
使用 format 控制输入框展示格式,使用 value-format 控制绑定值格式。
默认接受并向外抛出 Date 对象。
Day.js 占位符列表见此处。
WARNING
注意大小写。
Emits Date object
Value:
Use value-format
Value:
Timestamp
Value:
面板内的日期时间格式
使用 date-format 与 time-format 控制下拉面板内输入区域的展示格式。
-
日期时间范围
将 type 设为 datetimerange 可选择日期时间范围。
Default
To
With shortcuts
To
范围选择的默认时间
在 datetimerange 下,起止日期默认时间为 00:00:00,可通过 default-time 修改。该属性为最多两个 Date 组成的数组:第一项对应开始日期的时间,第二项对应结束日期的时间。
Start and end date time 12:00:00
-
Start date time 12:00:00, end date time 08:00:00
-
自定义图标
可通过插槽自定义图标。
API
属性
| 名称 | 说明 | 类型 | 默认值 |
|---|---|---|---|
| model-value / v-model | 绑定值;范围选择时为长度 2 的数组 | number / string / Date / array | '' |
| readonly | 是否只读 | boolean | false |
| disabled | 是否禁用 | boolean | false |
| editable | 输入是否可编辑 | boolean | true |
| clearable | 是否显示清空按钮 | boolean | true |
| size | 输入框尺寸 | enum | default |
| placeholder | 非范围模式占位符 | string | — |
| start-placeholder | 范围模式开始占位符 | string | — |
| end-placeholder | 范围模式结束占位符 | string | — |
| arrow-control | 是否使用箭头按钮选择时间 | boolean | false |
| type | 选择器类型 | enum | date |
| format | 输入框展示格式 | string 参见日期格式 | YYYY-MM-DD HH:mm:ss |
| popper-class | 下拉面板的自定义类名 | string | — |
| popper-style | 下拉面板的自定义样式 | string / object | — |
| popper-options | Popper 配置,详见 popper.js | object | {} |
| fallback-placements | Tooltip 可能的位置列表 | array | ['bottom', 'top', 'right', 'left'] |
| placement | 下拉出现位置 | Placement | bottom |
| range-separator | 范围分隔符 | string | '-' |
| default-value | 可选,日历默认定位的日期 | object | — |
| default-time | 选中日期后的默认时间;未指定时为 00:00:00 | object | — |
| value-format | 可选,绑定值格式;未指定时为 Date | string 见 day.js 格式 | — |
| date-format | 可选,面板内日期展示格式 | string 见 day.js 格式 | YYYY-MM-DD |
| time-format | 可选,面板内时间展示格式 | string 见 day.js 格式 | HH:mm:ss |
| id | 同原生 id | string / array | — |
| name | 同原生 name | string | — |
| unlink-panels | 范围选择时是否解除左右面板联动 | boolean | false |
| prefix-icon | 自定义前缀图标组件 | string / Component | Date |
| clear-icon | 自定义清空图标组件 | string / Component | CircleClose |
| shortcuts | 快捷选项数组 | array | — |
| disabled-date | 判断某日是否禁用 | Function | — |
| disabled-hours | 返回不可选的小时数组 | Function | — |
| disabled-minutes | 返回不可选的分钟数组 | Function | — |
| disabled-seconds | 返回不可选的秒数组 | Function | — |
| cell-class-name | 单元格自定义类名 | Function | — |
| teleported | 是否将弹层挂载到 body | boolean | true |
| empty-values | 视为空的取值,见 config-provider | array | — |
| value-on-clear | 清空后的绑定值,见 config-provider | string / number / boolean / Function | — |
| show-now | 是否显示「此刻」按钮 | boolean | true |
| show-footer | 类型为 enum 时是否显示底部栏 | boolean | true |
| show-confirm | 是否显示确认按钮 | boolean | true |
| show-week-number | 是否显示周数 | boolean | false |
事件
| 名称 | 说明 | 类型 |
|---|---|---|
| change | 用户确认或点击外部关闭时触发 | Function |
| blur | 输入框失焦时触发 | Function |
| focus | 输入框聚焦时触发 | Function |
| clear | 点击清空时触发 | Function |
| calendar-change | 日历所选日期变化,仅 range 模式 | Function |
| panel-change | 点击导航切换年月时触发 | Function |
| visible-change | 下拉显示/隐藏时触发 | Function |
插槽
| 名称 | 说明 |
|---|---|
| default | 自定义单元格内容 |
| range-separator | 自定义范围分隔符 |
| prev-month | 上一月图标 |
| next-month | 下一月图标 |
| prev-year | 上一年图标 |
| next-year | 下一年图标 |
暴露
| 方法 | 说明 | 类型 |
|---|---|---|
| focus | 聚焦组件 | Function |
| blur | 使组件失焦 | Function |
类型声明
展开类型声明
ts
type Placement =
| 'top'
| 'top-start'
| 'top-end'
| 'bottom'
| 'bottom-start'
| 'bottom-end'
| 'left'
| 'left-start'
| 'left-end'
| 'right'
| 'right-start'
| 'right-end'