DatePicker

Date or time selecting, supports year/month/day/hour/minute/second custom selecting

Import

import { DatePicker } from  'mand-mobile-next'

Vue.createApp().component(DatePicker.name, DatePicker)

Code Examples

API

DatePicker Props

PropsDescriptionTypeDefaultNote
v-modelinitial selected dateDate/Arraynew Date()value is an Array including such as [23, 59, 59] when type is time or custom, otherwise value is a Date
typetype of selectionStringdatedate, time, datetime, custom
custom-typescustomized element contains 'yyyy', 'MM', 'dd', 'hh', 'mm', 'ss'Array-valid when type is custom
min-dateselectable min date(time)Date--
max-dateselectable max date(time)Date--
unit-textelement unit for text displayingArray['Year', 'Month', 'Day', 'Hour', 'Minute', 'Second']text-render for complex logic
text-rendercustomized option for text displayingFunction(typeFormat, column0Value, column1Value, ...): String-unit-text is invalid when using text-render, refer to Appendix
today-textdisplaying text of todayStringtodayuse & to take placeholder date, like &(today)
line-heightline height of optionsNumber45unit px
keep-indexkeep last stop position when the column data changesBooleanfalse-
is-viewinline-display in page, otherwise it shows as PopupBooleanfalse-
titletitle of date-pickerString--
describedescription of date-pickerString--
ok-textconfirmation textStringconfirm-
cancel-textcancellation textStringcancel-
mask-closablepicker will be closed when clicking maskStringtrue-

DatePicker Methods

getColumnValues(): columnsValue

Get all values of currently seleted items

Returns

PropsDescriptionType
columnsValuevalues of all selected items in the columnArray<{value, text, ...}>

DatePicker Events

@change(columnIndex, itemIndex, value)

Change selections of date picker

ParametersDescriptionType
columnIndexchange the index of columnNumber
itemIndexchange the index of selected itemNumber
valuechange the value of selected itemObject: {value, text, ...}
@confirm()

Confirm the selection of date picker(only when is-view is false

@cancel()

Cancel date picker's selection (only when is-view is false

@show()

Show date picker (only when is-view is false

@hide()

Hide date picker (only when is-view is false

Appendix

  • columnData

const columnData = [
  // year
  [
    {
      text: '2017年', // display year text
      value: 2017, // display year value
      typeFormat: 'yyyy' // the type of date: yyyy, MM, dd, hh, mm, ss
    }
  ],
  // month
  [
    {
      text: '1月', // display month text
      value: 1, // display month value
      typeFormat: 'MM' // the type of date: yyyy, MM, dd, hh, mm, ss
    }
  ],
  // day, hour, minute, second
  [
    ...,
  ]
]
  • textRender
  const MONTH_MAP = [
    'Jan',
    'Feb',
    'Mar',
    'Apr',
    'May',
    'Jun',
    'Jul',
    'Aug',
    'Sept',
    'Oct',
    'Nov',
    'Dec',
  ]

  const textRender = (
    typeFormat: string,
    columnValue: number
  ) => {
    if (typeFormat === 'MM') {
      return MONTH_MAP[columnValue - 1]
    }
    return
  }