VEUI

VEUI on GitHub
Play!中文

DatePicker Date picker

Examples

Single date

By default, clicking on a date in the drop-down layer can select a date. You can configure the clearable prop to allow clearing the selected value and use the placeholder prop to configure the placeholder text when nothing is selected.

Clearable

Customizable placeholder

Pick a day

Supports v-model with value type being the native Date.

Edit this demo on GitHubEdit
<template>
<article>
  <section>
    <h4>Clearable</h4>
    <veui-date-picker
      v-model="date"
      clearable
    />
  </section>
  <section>
    <h4>Customizable placeholder</h4>
    <veui-date-picker
      v-model="date2"
      placeholder="Pick a day"
    />
  </section>
</article>
</template>

<script>
import { DatePicker } from 'veui'

export default {
  components: {
    'veui-date-picker': DatePicker
  },
  data () {
    return {
      date: new Date(),
      date2: null
    }
  }
}
</script>

<style lang="less" scoped>
section:not(:last-child) {
  margin-bottom: 20px;
}

h4 {
  margin-top: 0;
}
</style>

Date ranges

When configuring the range prop, you can select a date range in the drop-down layer.

Clearable

开始日期
~
结束日期

Customizable placeholder

Pick a date range...
~

Supports v-model, with value type being [Date, Date] when selecting a date range.

Edit this demo on GitHubEdit
<template>
<article>
  <section>
    <h4>Clearable</h4>
    <veui-date-picker
      v-model="range"
      range
      clearable
    />
  </section>
  <section>
    <h4>Customizable placeholder</h4>
    <veui-date-picker
      v-model="range"
      class="custom"
      range
      placeholder="Pick a date range..."
    />
  </section>
</article>
</template>

<script>
import { DatePicker } from 'veui'

export default {
  components: {
    'veui-date-picker': DatePicker
  },
  data () {
    return {
      range: null
    }
  }
}
</script>

<style lang="less" scoped>
section:not(:last-child) {
  margin-bottom: 20px;
}

h4 {
  margin-top: 0;
}
</style>

Shortcut options

When selecting a date range, you can provide shortcut options by configuring the shortcuts prop.

开始日期
~
结束日期
Edit this demo on GitHubEdit
<template>
<article>
  <veui-date-picker
    v-model="range"
    :shortcuts="shortcuts"
    range
    clearable
  />
</article>
</template>

<script>
import { DatePicker } from 'veui'

export default {
  components: {
    'veui-date-picker': DatePicker
  },
  data () {
    return {
      range: null,
      shortcuts: [
        {
          label: '上个月',
          from: {
            startOf: 'month',
            month: -1
          },
          to: {
            startOf: 'month',
            days: -1
          }
        },
        {
          label: '本月',
          from: {
            startOf: 'month'
          },
          to: 0
        },
        {
          label: '本周',
          from: {
            startOf: 'week',
            days: 0
          },
          to: 0
        },
        {
          label: '最近7天',
          from: -6,
          to: 0
        },
        {
          label: '今天',
          to: 0
        }
      ]
    }
  }
}
</script>

Disabled and read-only

Setting the disabled prop makes the component disabled.

Setting the readonly prop makes the component read-only.

Disabled

Readonly

Edit this demo on GitHubEdit
<template>
<article>
  <section>
    <h4>Disabled</h4>
    <veui-date-picker
      v-model="date"
      disabled
      placeholder="disabled"
    />
  </section>
  <section>
    <h4>Readonly</h4>
    <veui-date-picker
      v-model="date"
      readonly
      placeholder="readonly"
    />
  </section>
</article>
</template>

<script>
import { DatePicker } from 'veui'

export default {
  components: {
    'veui-date-picker': DatePicker
  },
  data () {
    return {
      date: new Date()
    }
  }
}
</script>

<style lang="less" scoped>
section:not(:last-child) {
  margin-bottom: 20px;
}

h4 {
  margin-top: 0;
}
</style>

API

Props

NameTypeDefaultDescription
typestring'date'The type of the calendar, with available values of 'date' / 'month' / 'year', corresponding to the date / month / year view.
rangebooleanfalseWhether to select a date range.
selectedDate | Array-

v-model

The value(s) of the selected date range, depending on the value of the range prop.

rangeType
falseDate
true[Date, Date]
todayDatenew Date()The date for "today".
week-startnumbercalendar.weekStartThe start of the week. Can be configured globally.
fill-monthbooleantrueWhen there is only one panel, whether to display non-current month dates in the current month panel.
date-classstring | Array | Object | function{}Custom HTML class for specific dates. When passed a non-function, the data format is all Vue-supported class expressions; when passed a function, the signature is function(Date): string | Array<string>|Object<string, boolean>, and the return value format is also all Vue-supported class expressions.
disabled-datefunction(Date, Date=): boolean() => falseUsed to customize whether a specified date is disabled. The first parameter is the date to be tested for disableness. When in the process of selecting a range and a date has already been selected, it will be passed as the second parameter.
clearablebooleanfalseWhether the selected value can be cleared.
placeholderstringrange ? datepicker.rangePlaceholder : datepicker.placeholderThe placeholder text when nothing is selected. Can be configured globally for date ranges and single dates.
formatstring | function(Date): string'yyyy-MM-dd' / 'yyyy-MM' / 'yyyy'When passed a string, it represents the string expression used for formatting/parsing, with specific formats available in the date-fns documentation. When passed a function, custom formatting logic can be defined.
parsefunction(string): Date-A function that customizes the parsing of input strings into Date objects.
shortcutsArray<Object>datepicker.shortcuts

A list of shortcut selection items in the customizable overlay when selecting a range, in the format Array<{label, from, to}>. Can be globally configured. See the corresponding configuration.

NameTypeDescription
labelstringThe text of the shortcut option.
fromThe calculation method for the start time, as described in the [Shortcut options](#shortcut-options) below.
toThe calculation method for the end time, as described in the [Shortcut options](#shortcut-options) below.
expandedbooleanfalse

.sync

Whether the dropdown overlay is expanded.

disabledbooleanfalseWhether the component is disabled.
readonlybooleanfalseWhether the component is readonly.

Shortcut options

The from and to properties in the shortcuts list items have the same format, each used to set the calculation method for the start and end dates, respectively. The format is number | Object with a default value of 0.

  • When the type is number, it represents the number of days offset from "today". For example, -1 is equivalent to { startOf: 'day', days: -1 }, which means "yesterday".

  • When the type is Object, the supported formats are: {startOf: string=, days: number=, weeks: number=, months: number=, }.

    NameTypeDefaultDescription
    startOfstring'day'The base date for the start. Supported values are 'day', 'week', 'month', 'quarter', 'year'.
    daynumber-The number of days offset.
    weeknumber-The number of weeks offset.
    monthnumber-The number of months offset.
    quarternumber-The number of quarters offset.
    yearnumber-The number of years offset.

The calculation method sets the base date according to startOf, and then adds the offset based on the other properties.

You can quickly set shortcut options by combining the following example with label.

[
  {
    label: 'Last month',
    // The first day of this month is one month ago, i.e. the first day of last month
    from: {
      startOf: 'month',
      month: -1
    },
    // One day before the first day of this month, i.e. the last day of last month
    to: {
      startOf: 'month',
      days: -1
    }
  },
  {
    label: 'This month',
    // The first day of this month
    from: {
      startOf: 'month'
    },
    // Today
    to: 0
  },
  {
    label: 'This week',
    // The first day of this week, days can be omitted when it is 0
    from: {
      startOf: 'week',
      days: 0
    },
    // Today
    to: 0
  },
  {
    label: 'Last 7 days',
    // Six days ago
    from: -6,
    // Until today
    to: 0
  },
  {
    label: 'Today',
    to: 0
  }
]

Slots

NameDescription
date

The area inside the single day unit cell of the calendar in the overlay, which can be used to customize the content of the corresponding area for each day.

Default content: The date corresponding to the date.

NameTypeDescription
yearnumberFull year.
monthnumberMonth number, 0 means January.
datenumberDate in the month.

Events

NameDescription
select

Triggered after selection is modified, callback parameter is (selected). Data type is consistent with the selected prop.

selectstartTriggered when the starting date is selected when selecting a date range, callback parameter (picking: Date), representing the selected starting date.
selectprogress

Triggered when the end date marked by mouse or keyboard interaction is changed after the start date has been selected when selecting a date range. The callback parameter is (picking), which represents the current marked date range, and the type depends on the value of the multiple prop.

multipleType
false[Date, Date]
trueArray<[Date, Date]>
toggleTriggered when the dropdown overlay expansion state is toggled, callback parameter is (expanded: boolean). expanded indicates whether the operation will trigger the dropdown overlay expansion or collapse.

Configs

KeyTypeDefaultDescription
datepicker.shortcutsArray[]Shortcut options configuration.
datepicker.placeholderstring@@datepicker.selectDatePlaceholder text when a single date has not been selected.
datepicker.monthPlaceholderstring@@datepicker.selectMonthPlaceholder text when a month has not been selected.
datepicker.yearPlaceholderstring@@datepicker.selectYearPlaceholder text when a year has not been selected.
datepicker.rangePlaceholderstring@@datepicker.selectRangePlaceholder text when a date range has not been selected.
datepicker.monthRangePlaceholderstring@@datepicker.selectMonthRangePlaceholder text when a month range has not been selected.
datepicker.yearRangePlaceholderstring@@datepicker.selectYearRangePlaceholder text when a year range has not been selected.

Icons

NameDescription
calendarThe calendar icon.
clearThe clear content icon.
Edit this page on GitHubEdit
© Baidu, Inc. 2024