/*! For license information please see 8201.ff1d9b9a.js.LICENSE.txt */ (self.webpackChunk=self.webpackChunk||[]).push([["8201"],{49871:function(t,n,s){"use strict";s.r(n);var a=s("80681");let e=["innerHTML"];n.default={setup:()=>({html:""}),render:()=>((0,a.wg)(),(0,a.iD)("div",{class:"van-doc-markdown-body",innerHTML:'
Calendar component for selecting dates or date ranges.
\nRegister component globally via app.use
, refer to Component Registration for more registration ways.
import { createApp } from 'vue';\nimport { Calendar } from 'vant';\n\nconst app = createApp();\napp.use(Calendar);\n
\nThe confirm
event will be emitted after the date selection is completed.
<van-cell title="Select Single Date" :value="date" @click="show = true" />\n<van-calendar v-model:show="show" @confirm="onConfirm" />\n
\nimport { ref } from 'vue';\n\nexport default {\n setup() {\n const date = ref('');\n const show = ref(false);\n\n const formatDate = (date) => `${date.getMonth() + 1}/${date.getDate()}`;\n const onConfirm = (value) => {\n show.value = false;\n date.value = formatDate(value);\n };\n\n return {\n date,\n show,\n onConfirm,\n };\n },\n};\n
\n<van-cell title="Select Multiple Date" :value="text" @click="show = true" />\n<van-calendar v-model:show="show" type="multiple" @confirm="onConfirm" />\n
\nimport { ref } from 'vue';\n\nexport default {\n setup() {\n const text = ref('');\n const show = ref(false);\n\n const onConfirm = (dates) => {\n show.value = false;\n text.value = `\u9009\u62E9\u4E86 ${dates.length} \u4E2A\u65E5\u671F`;\n };\n\n return {\n text,\n show,\n onConfirm,\n };\n },\n};\n
\nYou can select a date range after setting type
torange
. In range mode, the date returned by the confirm
event is an array, the first item in the array is the start time and the second item is the end time.
<van-cell title="Select Date Range" :value="date" @click="show = true" />\n<van-calendar v-model:show="show" type="range" @confirm="onConfirm" />\n
\nimport { ref } from 'vue';\n\nexport default {\n setup() {\n const date = ref('');\n const show = ref(false);\n\n const formatDate = (date) => `${date.getMonth() + 1}/${date.getDate()}`;\n const onConfirm = (values) => {\n const [start, end] = values;\n show.value = false;\n date.value = `${formatDate(start)} - ${formatDate(end)}`;\n };\n\n return {\n date,\n show,\n onConfirm,\n };\n },\n};\n
\nSet show-confirm
to false
to hide the confirm button. In this case, the confirm
event will be emitted immediately after the selection is completed.
<van-calendar v-model:show="show" :show-confirm="false" />\n
\nUse color
prop to custom calendar color.
<van-calendar v-model:show="show" color="#ee0a24" />\n
\nUse min-date
and max-date
to custom date range.
<van-calendar v-model:show="show" :min-date="minDate" :max-date="maxDate" />\n
\nimport { ref } from 'vue';\n\nexport default {\n setup() {\n const show = ref(false);\n\n return {\n show,\n minDate: new Date(2010, 0, 1),\n maxDate: new Date(2010, 0, 31),\n };\n },\n};\n
\nUse confirm-text
and confirm-disabled-text
to custom confirm text.
<van-calendar\n v-model:show="show"\n type="range"\n confirm-text="OK"\n confirm-disabled-text="Select End Time"\n/>\n
\nUse formatter
to custom day text.
<van-calendar v-model:show="show" type="range" :formatter="formatter" />\n
\nexport default {\n setup() {\n const formatter = (day) => {\n const month = day.date.getMonth() + 1;\n const date = day.date.getDate();\n\n if (month === 5) {\n if (date === 1) {\n day.topInfo = 'Labor Day';\n } else if (date === 4) {\n day.topInfo = 'Youth Day';\n } else if (date === 11) {\n day.text = 'Today';\n }\n }\n\n if (day.type === 'start') {\n day.bottomInfo = 'In';\n } else if (day.type === 'end') {\n day.bottomInfo = 'Out';\n }\n\n return day;\n };\n\n return {\n formatter,\n };\n },\n};\n
\nUse position
to custom popup position, can be set to top
\u3001left
\u3001right
.
<van-calendar v-model:show="show" :round="false" position="right" />\n
\nWhen selecting a date range, you can use the max-range
prop to specify the maximum number of selectable days.
<van-calendar type="range" :max-range="3" :style="{ height: '500px' }" />\n
\nUse first-day-of-week
to custom the start day of week
<van-calendar first-day-of-week="1" />\n
\nSet poppable
to false
, the calendar will be displayed directly on the page instead of appearing as a popup
<van-calendar\n title="Calendar"\n :poppable="false"\n :show-confirm="false"\n :style="{ height: '500px' }"\n/>\n
\nAttribute | \nDescription | \nType | \nDefault | \n
---|---|---|---|
type | \nType, can be set to range multiple | \nstring | \nsingle | \n
title | \nTitle of calendar | \nstring | \nCalendar | \n
color | \nColor for the bottom button and selected date | \nstring | \n#1989fa | \n
min-date | \nMin date | \nDate | \nToday | \n
max-date | \nMax date | \nDate | \nSix months after the today | \n
default-date | \nDefault selected date | \nDate | Date[] | null | \nToday | \n
row-height | \nRow height | \nnumber | string | \n64 | \n
formatter | \nDay formatter | \n(day: Day) => Day | \n- | \n
poppable | \nWhether to show the calendar inside a popup | \nboolean | \ntrue | \n
lazy-render | \nWhether to enable lazy render | \nboolean | \ntrue | \n
show-mark | \nWhether to show background month mark | \nboolean | \ntrue | \n
show-title | \nWhether to show title | \nboolean | \ntrue | \n
show-subtitle | \nWhether to show subtitle | \nboolean | \ntrue | \n
show-confirm | \nWhether to show confirm button | \nboolean | \ntrue | \n
readonly | \nWhether to be readonly | \nboolean | \nfalse | \n
confirm-text | \nConfirm button text | \nstring | \nConfirm | \n
confirm-disabled-text | \nConfirm button text when disabled | \nstring | \nConfirm | \n
first-day-of-week | \nSet the start day of week | \n0-6 | \n0 | \n
Following props are supported when the poppable is true
\nAttribute | \nDescription | \nType | \nDefault | \n
---|---|---|---|
v-model:show | \nWhether to show calendar | \nboolean | \nfalse | \n
position | \nPopup position, can be set to top right left | \nstring | \nbottom | \n
round | \nWhether to show round corner | \nboolean | \ntrue | \n
close-on-popstate | \nWhether to close when popstate | \nboolean | \ntrue | \n
close-on-click-overlay | \nWhether to close when overlay is clicked | \nboolean | \ntrue | \n
safe-area-inset-top | \nWhether to enable top safe area adaptation | \nboolean | \nfalse | \n
safe-area-inset-bottom | \nWhether to enable bottom safe area adaptation | \nboolean | \ntrue | \n
teleport | \nSpecifies a target element where Calendar will be mounted | \nstring | Element | \n- | \n
Following props are supported when the type is range
\nAttribute | \nDescription | \nType | \nDefault | \n
---|---|---|---|
max-range | \nNumber of selectable days | \nnumber | string | \nUnlimited | \n
range-prompt | \nError message when exceeded max range | \nstring | \nChoose no more than xx days | \n
show-range-prompt | \nWhether prompt error message when exceeded max range | \nboolean | \ntrue | \n
allow-same-day | \nWhether the start and end time of the range is allowed on the same day | \nboolean | \nfalse | \n
Following props are supported when the type is multiple
\nAttribute | \nDescription | \nType | \nDefault | \n
---|---|---|---|
max-range | \nMax count of selectable days | \nnumber | string | \nUnlimited | \n
range-prompt | \nError message when exceeded max count | \nstring | \nChoose no more than xx days | \n
Key | \nDescription | \nType | \n
---|---|---|
date | \nDate | \nDate | \n
type | \nType, can be set to selected \u3001start \u3001middle \u3001end \u3001disabled | \nstring | \n
text | \nText | \nstring | \n
topInfo | \nTop info | \nstring | \n
bottomInfo | \nBottom info | \nstring | \n
className | \nExtra className | \nstring | \n
Event | \nDescription | \nArguments | \n
---|---|---|
select | \nEmitted when date is selected | \nvalue: Date | Date[] | \n
confirm | \nEmitted after date selection is complete, if show-confirm is true , it is Emitted after clicking the confirm button | \nvalue: Date | Date[] | \n
open | \nEmitted when opening Popup | \n- | \n
close | \nEmitted when closing Popup | \n- | \n
opened | \nEmitted when Popup is opened | \n- | \n
closed | \nEmitted when Popup is closed | \n- | \n
unselect | \nEmitted when unselect date when type is multiple | \nvalue: Date | \n
month-show | \nEmitted when a month enters the visible area | \nvalue: { date: Date, title: string } | \n
over-range | \nEmitted when exceeded max range | \n- | \n
click-subtitle | \nEmitted when clicking the subtitle | \nevent: MouseEvent | \n
click-disabled-date v4.7.0 | \nEmitted when clicking disabled date | \nvalue: Date | Date[] | \n
Name | \nDescription | \nSlotProps | \n
---|---|---|
title | \nCustom title | \n- | \n
subtitle | \nCustom subtitle | \n{ text: string, date?: Date } | \n
month-title v4.0.9 | \nCustom title of every month | \n{ text: string, date: Date } | \n
footer | \nCustom footer | \n- | \n
confirm-text | \nCustom confirm text | \n{ disabled: boolean } | \n
top-info | \nCustom top info of day | \nday: Day | \n
bottom-info | \nCustom bottom info of day | \nday: Day | \n
Use ref to get Calendar instance and call instance methods.
\nName | \nDescription | \nAttribute | \nReturn value | \n
---|---|---|---|
reset | \nReset selected date, will reset to default date when no params passed | \ndate?: Date | Date[] | \n- | \n
scrollToDate | \nScroll to date | \ndate: Date | \n- | \n
getSelectedDate | \nget selected date | \n- | \nDate | Date[] | null | \n
The component exports the following type definitions:
\nimport type {\n CalendarType,\n CalendarProps,\n CalendarDayItem,\n CalendarDayType,\n CalendarInstance,\n} from 'vant';\n
\nCalendarInstance
is the type of component instance:
import { ref } from 'vue';\nimport type { CalendarInstance } from 'vant';\n\nconst calendarRef = ref<CalendarInstance>();\n\ncalendarRef.value?.reset();\n
\nThe component provides the following CSS variables, which can be used to customize styles. Please refer to ConfigProvider component.
\nName | \nDefault Value | \nDescription | \n
---|---|---|
--van-calendar-background | \nvar(--van-background-2) | \n- | \n
--van-calendar-popup-height | \n80% | \n- | \n
--van-calendar-header-shadow | \n0 2px 10px rgba(125, 126, 128, 0.16) | \n- | \n
--van-calendar-header-title-height | \n44px | \n- | \n
--van-calendar-header-title-font-size | \nvar(--van-font-size-lg) | \n- | \n
--van-calendar-header-subtitle-font-size | \nvar(--van-font-size-md) | \n- | \n
--van-calendar-weekdays-height | \n30px | \n- | \n
--van-calendar-weekdays-font-size | \nvar(--van-font-size-sm) | \n- | \n
--van-calendar-month-title-font-size | \nvar(--van-font-size-md) | \n- | \n
--van-calendar-month-mark-color | \nfade(var(--van-gray-2), 80%) | \n- | \n
--van-calendar-month-mark-font-size | \n160px | \n- | \n
--van-calendar-day-height | \n64px | \n- | \n
--van-calendar-day-font-size | \nvar(--van-font-size-lg) | \n- | \n
--van-calendar-day-margin-bottom | \n4px | \n- | \n
--van-calendar-range-edge-color | \nvar(--van-white) | \n- | \n
--van-calendar-range-edge-background | \nvar(--van-primary-color) | \n- | \n
--van-calendar-range-middle-color | \nvar(--van-primary-color) | \n- | \n
--van-calendar-range-middle-background-opacity | \n0.1 | \n- | \n
--van-calendar-selected-day-size | \n54px | \n- | \n
--van-calendar-selected-day-color | \nvar(--van-white) | \n- | \n
--van-calendar-info-font-size | \nvar(--van-font-size-xs) | \n- | \n
--van-calendar-info-line-height | \nvar(--van-line-height-xs) | \n- | \n
--van-calendar-selected-day-background | \nvar(--van-primary-color) | \n- | \n
--van-calendar-day-disabled-color | \nvar(--van-text-color-3) | \n- | \n
--van-calendar-confirm-button-height | \n36px | \n- | \n
--van-calendar-confirm-button-margin | \n7px 0 | \n- | \n