zebra-ui基于uniapp,跨多端组件库
  • 2.x
  • 中文
开发指南
介绍
快速上手
进阶用法
常见问题
更新日志
贡献指南
国际化
基础组件
Button 按钮
Cell 单元格
ConfigProvider 全局配置
Icon 图标
Image 图片
Layout 布局
Popup 弹出层
Style 内置样式
Transition 动画
Toast 轻提示
表单组件
Area 省市区选择
Calendar 日历
Cascader 级联选择
Checkbox 复选框
DatePicker 日期选择
Field 输入框
Form 表单
NumberKeyboard 数字键盘
PasswordInput 密码输入框
Picker 选择器
PickerGroup 选择器组
Radio 单选框
Rate 评分
Search 搜索
Slider 滑块
Signature 签名
Stepper 步进器
Switch 开关
TimePicker 时间选择
Uploader 文件上传
反馈组件
ActionSheet 动作面板
Barrage 弹幕
Dialog 弹出框
DropdownMenu 下拉菜单
FloatingPanel 浮动面板
FloatingBubble 浮动气泡
Loading 加载
Notify 消息通知
Overlay 遮罩层
PullRefresh 下拉刷新
ShareSheet 分享面板
SwipeCell 滑动单元格
展示组件
Badge 徽标
Circle 环形进度条
Collapse 折叠面板
CountDown 倒计时
Divider 分割线
Empty 空状态
Highlight 高亮文本
List 列表
NoticeBar 通知栏
Popover 气泡弹出框
Progress 进度条
RollingText 翻滚文本
Skeleton 骨架屏
Steps 步骤条
Sticky 粘性布局
Swipe 轮播
Tag 标签
TextEllipsis 文本省略
Watermark 水印
导航组件
Grid 宫格
NavBar 导航栏
Sidebar 侧边导航
Tab 标签页
Tabbar 标签栏
TreeSelect 分类选择

DatePicker date selection

introduce

Date picker, used to select year, month, day, usually used in conjunction with the popup layer (/popup) component.

Code Demo

Basic usage

Bind the currently selected date through v-model, and set the optional time range through min-date and max-date attributes.

<z-date-picker
   v-model="currentDate"
   title="Select date"
   :min-date="minDate"
   :max-date="maxDate"
/>
const currentDate = ref(['2021', '01', '01'])
const minDate = new Date(2020, 0, 1)
const maxDate = new Date(2025, 5, 1)

Option type

The type of options can be controlled through the columns-type attribute, which supports permutations and combinations of year, month and day in any order.

for example:

  • Pass ['year'] to select the year individually.
  • Pass ['month'] to select months individually.
  • Pass in ['year', 'month'] to select year and month.
  • Pass in ['month', 'day'] to select month and day.
<z-date-picker
   v-model="currentDate"
   title="Select year and month"
   :min-date="minDate"
   :max-date="maxDate"
   :columns-type="columnsType"
/>
import { ref } from 'vue';
const currentDate = ref(['2021', '01']);
const columnsType = ['year', 'month'];
const minDate = new Date(2020, 0, 1)
const maxDate = new Date(2025, 5, 1)

Format options

By passing in the formatter function, the option text can be formatted.

<z-date-picker
   v-model="currentDateFormatter"
   title="Select year and month"
   :min-date="minDate"
   :max-date="maxDate"
   :formatter="formatter"
   :columns-type="columnsType"
/>
import { ref } from 'vue';
const currentDateFormatter = ref(['2021', '01'])
const minDate = new Date(2020, 0, 1)
const maxDate = new Date(2025, 5, 1)
const columnsType = ['year', 'month']
const formatter = (type: any, option: any) => {
   if (type === 'year') {
     option.text += 'year'
   }
   if (type === 'month') {
     option.text += 'month'
   }
   return option
}

Filter options

By passing in the filter function, the option array can be filtered to implement custom option intervals.

<z-date-picker
   v-model="currentDateFilter"
   title="Select year and month"
   :filter="filter"
   :min-date="minDate"
   :max-date="maxDate"
   :columns-type="columnsType"
/>
import { ref } from 'vue';

const filter = (type: string, options: any) => {
   if (type === 'month') {
     return options.filter((option: any) => Number(option.value) % 6 === 0)
   }
   return options
}

API

Props

ParametersDescriptionTypeDefault value
v-modelCurrently selected datestring[]
columns-typeOption type, array of year, month and daystring['year', 'month', 'day']
min-dateOptional minimum time, accurate to dayDate-
max-dateOptional maximum time, accurate to dayDate-
titleTop column titlestring''
confirm-button-textConfirm button textstringConfirm
cancel-button-textCancel button textstringCancel
show-toolbarWhether to display the top barbooleantrue
loadingwhether to display loading statusbooleanfalse
readonlyWhether it is in read-only state. Options cannot be switched in read-only statebooleanfalse
filteroption filter function(type: string, options: PickerOption) => PickerOption-
formatteroption formatting function(type: string, option: PickerOption) => PickerOption-
option-heightOption height, supports rpx unit, default pxnumber | string44
visible-option-numNumber of visible optionsnumber | string6
swipe-durationThe duration of inertial scrolling during fast swiping, unit msnumber | string1000

Events

Event nameDescriptionCallback parameters
confirmTriggered when the completion button is clicked{ selectedValues, selectedOptions, selectedIndexes }
cancelTriggered when the cancel button is clicked{ selectedValues, selectedOptions, selectedIndexes }
changeTriggered when options change{ selectedValues, selectedOptions, selectedIndexes, columnIndex }

Slots

NameDescriptionParameters
toolbarCustomize the entire top bar content-
titleCustom title content-
confirmCustomize the confirmation button content-
cancelCustomize cancel button content-
optionCustom option contentoption: PickerOption, index: number
columns-topCustomize the content above the options-
columns-bottomCustomize the content below the options-