/*! For license information please see 4206.281f427c.js.LICENSE.txt */ (self.webpackChunk=self.webpackChunk||[]).push([["4206"],{88515:function(s,n,a){"use strict";a.r(n);var t=a("80681");let e=["innerHTML"];n.default={setup:()=>({html:""}),render:()=>((0,t.wg)(),(0,t.iD)("div",{class:"van-doc-markdown-body",innerHTML:'

DatePicker

\n

Intro

\n

Used to select date, usually used with the Popup component.

\n

Install

\n

Register component globally via app.use, refer to Component Registration for more registration ways.

\n
import { createApp } from 'vue';\nimport { DatePicker } from 'vant';\n\nconst app = createApp();\napp.use(DatePicker);\n
\n

Usage

\n

Basic Usage

\n
<van-date-picker\n  v-model="currentDate"\n  title="Choose Date"\n  :min-date="minDate"\n  :max-date="maxDate"\n/>\n
\n
import { ref } from 'vue';\n\nexport default {\n  setup() {\n    const currentDate = ref(['2021', '01', '01']);\n    return {\n      minDate: new Date(2020, 0, 1),\n      maxDate: new Date(2025, 5, 1),\n      currentDate,\n    };\n  },\n};\n
\n

Columns Type

\n

Using columns-type prop to control the type of columns.

\n

For example:

\n\n
<van-date-picker\n  v-model="currentDate"\n  title="Choose Year-Month"\n  :min-date="minDate"\n  :max-date="maxDate"\n  :columns-type="columnsType"\n/>\n
\n
import { ref } from 'vue';\n\nexport default {\n  setup() {\n    const currentDate = ref(['2021', '01']);\n    const columnsType = ['year', 'month'];\n    return {\n      minDate: new Date(2020, 0, 1),\n      maxDate: new Date(2025, 5, 1),\n      currentDate,\n      columnsType,\n    };\n  },\n};\n
\n

Options Formatter

\n
<van-date-picker\n  v-model="currentDate"\n  title="Choose Year-Month"\n  :min-date="minDate"\n  :max-date="maxDate"\n  :formatter="formatter"\n  :columns-type="columnsType"\n/>\n
\n
import { ref } from 'vue';\n\nexport default {\n  setup() {\n    const currentDate = ref(['2021', '01']);\n    const columnsType = ['year', 'month'];\n\n    const formatter = (type, option) => {\n      if (type === 'year') {\n        option.text += ' Year';\n      }\n      if (type === 'month') {\n        option.text += 'Month';\n      }\n      return option;\n    };\n\n    return {\n      minDate: new Date(2020, 0, 1),\n      maxDate: new Date(2025, 5, 1),\n      formatter,\n      currentDate,\n      columnsType,\n    };\n  },\n};\n
\n

Options Filter

\n
<van-date-picker\n  v-model="currentDate"\n  title="Choose Year-Month"\n  :filter="filter"\n  :min-date="minDate"\n  :max-date="maxDate"\n  :columns-type="columnsType"\n/>\n
\n
import { ref } from 'vue';\n\nexport default {\n  setup() {\n    const currentDate = ref(['2021', '01']);\n    const columnsType = ['year', 'month'];\n    const filter = (type, options) => {\n      if (type === 'month') {\n        return options.filter((option) => Number(option.value) % 6 === 0);\n      }\n      return options;\n    };\n\n    return {\n      filter,\n      minDate: new Date(2020, 0, 1),\n      maxDate: new Date(2025, 5, 1),\n      currentTime,\n      columnsType,\n    };\n  },\n};\n
\n

API

\n

Props

\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n
AttributeDescriptionTypeDefault
v-modelCurrent datestring[][]
columns-typeColumns typestring[][\'year\', \'month\', \'day\']
min-dateMin dateDateTen years ago on January 1
max-dateMax dateDateTen years later on December 31
titleToolbar titlestring\'\'
confirm-button-textText of confirm buttonstringConfirm
cancel-button-textText of cancel buttonstringCancel
show-toolbarWhether to show toolbarbooleantrue
loadingWhether to show loading promptbooleanfalse
readonlyWhether to be readonlybooleanfalse
filterOption filter(type: string, options: PickerOption[]) => PickerOption[]-
formatterOption formatter(type: string, option: PickerOption) => PickerOption-
option-heightOption height, supports px vw vh rem unit, default pxnumber | string44
visible-option-numCount of visible columnsnumber | string6
swipe-durationDuration of the momentum animation, unit msnumber | string1000
\n

Events

\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n
EventDescriptionArguments
confirmEmitted when the confirm button is clicked{ selectedValues, selectedOptions, selectedIndexes }
cancelEmitted when the cancel button is clicked{ selectedValues, selectedOptions, selectedIndexes }
changeEmitted when current option is changed{ selectedValues, selectedOptions, selectedIndexes, columnIndex }
\n

Slots

\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n
NameDescriptionSlotProps
toolbarCustom toolbar content-
titleCustom title-
confirmCustom confirm button text-
cancelCustom cancel button text-
optionCustom option contentoption: PickerOption, index: number
columns-topCustom content above columns-
columns-bottomCustom content below columns-
\n

Methods

\n

Use ref to get Picker instance and call instance methods.

\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n
NameDescriptionAttributeReturn value
confirmStop scrolling and emit confirm event--
getSelectedDateGet current selected date-string[]
\n

Types

\n

The component exports the following type definitions:

\n
import type {\n  DatePickerProps,\n  DatePickerColumnType,\n  DatePickerInstance,\n} from 'vant';\n
\n

DatePickerInstance is the type of component instance:

\n
import { ref } from 'vue';\nimport type { DatePickerInstance } from 'vant';\n\nconst datePickerRef = ref<DatePickerInstance>();\n\ndatePickerRef.value?.confirm();\n
\n
'},null,8,e))}}}]);