Skip to content

Calendar 日历

用于展示月视图日历,支持假日标记、范围选择、多选、自定义单元格内容以及组件级主题覆盖。

基础用法

通过 v-model 绑定当前选中的日期。

2026年4月
29
30
31
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
1
2
3
4
5
6
7
8
9
基础用法

假日标记

开启 show-holiday 后,组件会合并内置的 2026 中国节假日数据与传入的 holidays

2026年4月
29
30
31
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
1
2
3
4
5
6
7
8
9
假日标记

自定义日期单元格

使用 date-cell 插槽可在日期格中追加业务标记。

2026年4月
29
30
31
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
1
2
3
4
5
6
7
8
9
自定义日期单元格

范围选择

设置 selection-mode="range" 后,通过 v-model:range-value 接收起止日期。

2026年4月
29
30
31
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
1
2
3
4
5
6
7
8
9

请选择开始日期

范围选择

多选

设置 selection-mode="multiple" 后,通过 v-model:multiple-value 维护多选日期数组。

2026年4月
29
30
31
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
1
2
3
4
5
6
7
8
9
多选

日期限制

可以组合 min-datemax-datedisabled-date 实现可选范围限制。

2026年4月
29
30
31
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
1
2
3
4
5
6
7
8
9
日期限制

周数与尺寸

日历支持显示周数,也支持 smalldefaultlarge 三种尺寸。

2026年4月
13
29
30
31
1
2
3
4
14
5
6
7
8
9
10
11
15
12
13
14
15
16
17
18
16
19
20
21
22
23
24
25
17
26
27
28
29
30
1
2
18
3
4
5
6
7
8
9
显示周数
2026年4月
29
30
31
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
1
2
3
4
5
6
7
8
9
2026年4月
29
30
31
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
1
2
3
4
5
6
7
8
9
2026年4月
29
30
31
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
1
2
3
4
5
6
7
8
9
不同尺寸

只读模式

设置 readonly 后仍会保留展示能力,但不会响应日期选择。

2026年4月
29
30
31
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
1
2
3
4
5
6
7
8
9
只读模式

在 Nuxt 中使用

安装 @yh-ui/nuxt 后可直接使用 YhCalendar。首屏静态日历、假日标记和插槽内容都可在 SSR 阶段正常输出,交互状态如范围悬停会在客户端激活后生效。

2026年4月
29
30
31
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
1
2
3
4
5
6
7
8
9
Nuxt 中使用

API

Props

属性名说明类型默认值
v-model / model-value单选模式下的绑定值Dateundefined
default-value默认选中日期Dateundefined
mode日历模式'month' | 'year''month'
first-day-of-week每周起始日,1 为周一,7 为周日number7
min-date最小可选日期Dateundefined
max-date最大可选日期Dateundefined
readonly是否只读booleanfalse
disabled是否禁用booleanfalse
month-header-format自定义标题格式stringundefined
show-holiday是否显示假日与补班标记booleanfalse
holidays自定义假日数据HolidayMap{}
show-week-number是否显示周数booleanfalse
fullscreen是否占满父容器高度booleanfalse
selection-mode选择模式'single' | 'range' | 'multiple''single'
range-value范围选择值[Date | undefined, Date | undefined]undefined
multiple-value多选值Date[][]
disabled-date自定义禁用日期判断(date: Date) => booleanundefined
cell-class-name单元格自定义类名(date: Date) => string | string[] | Record<string, boolean>undefined
show-other-months是否显示非当月日期booleantrue
highlight-weekends是否高亮周末booleantrue
size日历尺寸'small' | 'default' | 'large''default'
theme-overrides组件主题覆盖变量CalendarThemeVarsundefined

Events

事件名说明参数
update:modelValue单选值变化时触发(value: Date) => void
update:rangeValue范围选择完成时触发(value: [Date | undefined, Date | undefined]) => void
update:multipleValue多选值变化时触发(value: Date[]) => void
change单选值变化时触发(value: Date) => void
panel-change面板月份变化时触发(date: Date, mode: 'month' | 'year') => void
select选择日期单元格时触发(date: Date, cell: CalendarDateCell) => void
range-change范围选择完成时触发(value: [Date | undefined, Date | undefined]) => void

Slots

插槽名说明参数
header自定义头部标题{ date: string }
date-cell自定义日期单元格内容{ data: CalendarCellSlotData }
footer自定义底部区域-

CalendarCellSlotData 为运行时传入的插槽结构,包含以下字段:

字段类型说明
daystring格式化日期,如 2026-02-14
dateDate原生日期对象
type'prev-month' | 'current-month' | 'next-month'日期所属月份类型
isSelectedboolean是否被选中
isTodayboolean是否今天
isDisabledboolean是否禁用
isWeekendboolean是否周末
isHolidayboolean是否法定假日
holidayNamestring | undefined假日名称
isWorkdayboolean是否补班日
isInRangeboolean | undefined是否位于范围内部
isRangeStartboolean | undefined是否为范围起点
isRangeEndboolean | undefined是否为范围终点

Expose

名称说明类型
displayDate当前面板显示日期Ref<Dayjs>
selectedDate当前单选日期Ref<Dayjs | undefined>
moveMonth切换月份(delta: number) => void
goToday跳转到今天() => void
selectDate手动选中某个日期单元格(cell: CalendarDateCell) => void

类型导出

类型名说明
YhCalendarProps组件 Props 类型
YhCalendarEmits组件 Emits 类型
YhCalendarSlots组件 Slots 类型
YhCalendarExpose组件 Expose 类型
YhCalendarDateCell日期单元格类型
YhCalendarHolidayInfo假日信息类型
YhCalendarHolidayMap假日映射类型
YhCalendarRangeValue范围选择值类型
YhCalendarMode模式类型

主题变量

组件支持 themeOverrides,同时样式中实际消费以下 CSS 变量:

变量名说明默认值
--yh-calendar-primary主色var(--yh-color-primary)
--yh-calendar-primary-light主色浅色背景var(--yh-color-primary-light-9)
--yh-calendar-primary-dark主色深色态var(--yh-color-primary-dark-2)
--yh-calendar-bg日历背景var(--yh-bg-color)
--yh-calendar-text主文字色var(--yh-text-color-primary)
--yh-calendar-cell-height日期格高度100px
--yh-calendar-cell-radius日期格圆角var(--yh-radius-lg)
--yh-calendar-head-height头部高度80px
--yh-calendar-title-size标题字号22px
--yh-calendar-weekday-color星期标题颜色var(--yh-text-color-secondary)
--yh-calendar-week-number-color周数字颜色var(--yh-text-color-placeholder)
--yh-calendar-holiday-color假日标记颜色var(--yh-color-danger)
--yh-calendar-disabled-bg禁用态背景var(--yh-fill-color-light)
--yh-calendar-disabled-text禁用态文字色var(--yh-text-color-placeholder)

CalendarThemeVars 对外暴露的组件级主题覆盖字段包括: headerBgColorheaderTextColortitleFontSizedayFontSizedayTextColordayHoverBgColordaySelectedBgColordaySelectedTextColortodayTextColorweekendTextColor

Released under the MIT License.