Skip to content
广告位招租

优质广告位诚邀合作

本广告位曝光量正火速攀升,用户触达规模呈爆发式增长!现向品牌开放合作,趁曝光增长红利期,抓紧机会拿下,让您的品牌借势破圈!

--总浏览量(次)
--总计访客(人)

date

日期组件,默认情况下使用dict-date使用,如果字典包配置中有配置componentsPreFix字段,请根据此字段的具体配置值进行前缀修改,如配置了componentsPreFixBu, 则使用bu-date使用。

复制成功
00:00

注意

format 配置有要求,与datePickerColumnsType 配置息息相关,datePickerColumnsType存在year 则format必须存在 yyyy, 存在month则必须存在MM, 存在day则必须存在dd。

valueFormat 配置则必须是符合规则的日期格式字符串,可以是timestamp

上述 配置 datePickerColumnsType 将年月日 顺序弄返是有意为之,旨在说明配置format时,显示值将根据format配置进行展示;不配置format时,显示值将根据 datePickerColumnsType 配置顺序 进行展示。

组件结构

组件封装结构如下

vue
 <div class="van-date-picker-dict van-cell-dict">
    <van-field ref="VanFieldRef"></van-field>
    <van-popup ref="VanPopupRef">
      <van-date-picker ref="VanDatePickerRef"></van-date-picker>
    </van-popup>
 </div>
js
const VanFieldRef = ref(null)
const getVanFieldRef = () => {
  return VanFieldRef.value
}
const VanPopupRef = ref(null)
const getVanPopupRef = () => {
  return VanPopupRef.value
}
const VanDatePickerRef = ref(null)
const getVanDatePickerRef = () => {
  return VanDatePickerRef.value
}
defineExpose({ getVanFieldRef, getVanPopupRef, getVanDatePickerRef })
属性、事件和插槽继承技巧

此组件引用了van-fieldvan-popupvan-date-picker三个组件,其中van-field组件可直接继承原生属性、事件和插槽, van-popup继承属性、事件和插槽时添加 popup- 前缀即可,同理 van-date-picker组件则是添加 date-picker- 前缀

点击阅读field组件使用文档

点击阅读popup组件使用文档

点击阅读date-picker组件使用文档

属性

属性类型说明默认值
clearableBoolean是否可清除false
showArrowBoolean展示清除按钮时是否展示右边箭头true
spacerstring间隔符-
showForeverBoolean是否显示永久选项false
foreverLabelString永久选项对应中文名永久
foreverValueString永久选项对应值forever
datePickerColumnsTypestring[]选项类型,由 year、month 和 day 组成的数组['year', 'month', 'day']
formatString自定义显示格式 与datePickerColumnsType配置息息相关
sameInputBoolean绑定值的数据是否跟随显示值一致true
valueFormatString自定义显示格式 sameInput为false时生效,需为正常日期格式,默认为标准日期格式,timestamp 为时间戳
min-datev1.1.0String,Number,Date最小日期十年前的今天
max-datev1.1.0String,Number,Date最大日期十年后的今天
defaultDatev1.1.0String,Number,Date没值时打开的默认值默认值今天,当小于最小日期时为最小日期,当大于最大日期时为最大日期
defaultValv1.1.0stringmodelValue没值时的缺省代替显示值,默认为nullnull
openDefaultValJudgev1.1.0boolean是否当项目不可选时才显示defaultValtrue

事件

事件名称说明
dictChange选中值时触发此事件,并返回选中的值

提示

date-picker弹出框 顶部栏标题可 直接配置 title属性, date-picker-titledatePickerTitle 属性 也是有效

date-picker弹出框 顶部栏取消按钮文字可 直接配置 cancel-button-textcancelButtonText属性, date-picker-cancel-button-textdatePickerCancelButtonText 属性 也是有效

date-picker弹出框 顶部栏确认按钮文字可 直接配置 confirm-button-textconfirmButtonText属性, date-picker-confirm-button-textdatePickerConfirmButtonText 属性 也是有效

微信公众号【爆米花小布】

0%

置顶

置顶