日期选择器 DatePicker & DateSelect

基本用法

日期选择器 DatePicker - 图1

  1. <template>
  2. <div>
  3. <div class="demo-hidden">
  4. <za-panel>
  5. <za-panel-header title="日期选择器"></za-panel-header>
  6. <za-panel-body>
  7. <za-cell title="日期选择">
  8. <za-button slot='description' size='xs' @click='visible1 = true'>开启</za-button>
  9. </za-cell>
  10. <za-cell title="年份选择">
  11. <za-button slot='description' size='xs' @click='visible5 = true'>开启</za-button>
  12. </za-cell>
  13. <za-cell title="月份选择">
  14. <za-button slot='description' size='xs' @click='visible2 = true'>开启</za-button>
  15. </za-cell>
  16. <za-cell title="时间选择">
  17. <za-button slot='description' size='xs' @click='visible3 = true'>开启</za-button>
  18. </za-cell>
  19. <za-cell title="时间&日期">
  20. <za-button slot='description' size='xs' @click='visible4 = true'>开启</za-button>
  21. </za-cell>
  22. </za-panel-body>
  23. </za-panel>
  24. <za-date-picker
  25. :close-on-click-modal='false'
  26. :visible.sync='visible1'
  27. title="选择日期"
  28. placeholder="请选择日期"
  29. mode='date'
  30. max='2030-10-25'
  31. min='1917-02-12'
  32. @ok='handleOk'></za-date-picker>
  33. <za-date-picker
  34. :visible.sync='visible5'
  35. title="选择年份"
  36. defaultValue='2015'
  37. placeholder="请选择年份"
  38. mode='year'
  39. @ok='handleOk'></za-date-picker>
  40. <za-date-picker
  41. :visible.sync='visible2'
  42. title="选择月份"
  43. defaultValue='2018-09'
  44. placeholder="请选择月份"
  45. mode='month'
  46. @ok='handleOk'></za-date-picker>
  47. <za-date-picker
  48. :visible.sync='visible3'
  49. title="选择时间"
  50. defaultValue='2018-09-10 09:45'
  51. placeholder="请选择时间"
  52. mode='time'
  53. :minute-step='minuteStep'
  54. @ok='handleOk'></za-date-picker>
  55. <za-date-picker
  56. :visible.sync='visible4'
  57. title="选择"
  58. placeholder="请选择时间和日期"
  59. mode='datetime'
  60. @ok='handleOk'></za-date-picker>
  61. <za-panel>
  62. <za-panel-header title="日期选择器 Select"></za-panel-header>
  63. <za-panel-body>
  64. <za-cell title="日期选择">
  65. <za-date-select
  66. v-model='v5'
  67. title="选择日期"
  68. placeholder="请选择日期"
  69. mode='date'
  70. format='yyyy年MM月dd日'
  71. max='2030-10-25'
  72. min='1917-10-25'
  73. @ok='handleOk'></za-date-select>
  74. </za-cell>
  75. <za-cell title="日期格式化">
  76. <za-date-select
  77. v-model='v7'
  78. title="选择日期"
  79. placeholder="请选择日期"
  80. mode='datetime'
  81. value-format='yyyy-MM-dd HH:mm'
  82. max='2030-10-25'
  83. min='1917-10-25'
  84. @ok='handleOk'></za-date-select>
  85. </za-cell>
  86. </za-panel-body>
  87. </za-panel>
  88. <za-panel>
  89. <za-panel-header title="平铺日期选择器 DatePickerView"></za-panel-header>
  90. <za-panel-body>
  91. <za-date-picker-view
  92. title="选择年份"
  93. placeholder="请选择年份"
  94. mode='datetime'
  95. min="2018-01-13"
  96. max="2090-11-27"
  97. :defaultValue="v6"
  98. @change='handleChange'></za-date-picker-view>
  99. </za-panel-body>
  100. </za-panel>
  101. </div>
  102. </div>
  103. </template>
  104. <script>
  105. export default {
  106. data() {
  107. return {
  108. visible1: false,
  109. visible2: false,
  110. visible3: false,
  111. visible4: false,
  112. visible5: false,
  113. v1:'',
  114. v2:'',
  115. v3:'',
  116. v4:'',
  117. v5:'2008-01-10',
  118. v6:'2018-12-24 11:23',
  119. v7: '',
  120. minuteStep: 15,
  121. }
  122. },
  123. methods: {
  124. handleOk(v){
  125. console.log('it may still scrolling when ok is clicked. so ues v-model or @change instead')
  126. console.log(v);
  127. },
  128. handleChange(v){
  129. console.log(v);
  130. },
  131. handleCancel(event){
  132. console.log('cancelled');
  133. },
  134. displayGenerator(selected) {
  135. return selected.map(item => item.name).join('/')
  136. }
  137. },
  138. };
  139. </script>

API

Date Picker & Date Select Attributes

属性类型默认值可选值/参数说明
prefixClsstringza-picker类名前缀
visibleboolfalse是否显示, 支持.sync修饰符 (v2.3.0+)
default-valuestring初始值
v-modelstring绑定值
disabledboolfalse是否禁用
titlestring'请选择'选择器标题
placeholderstring'请选择'输入提示信息
modestringdateyear, date, time , datetime指定日期选择模式
formatstring例:yyyy年MM月dd日 年:yyyy, 月:MM, 日:dd, 时:HH, 分:mm格式化显示值
value-formatstring例:yyyy-MM-dd HH:mm格式化绑定值
maxstring例:2017-08-10
minstring例:2000-01-03
minuteStepnumber1分钟步长

Picker & Select Events

事件名称说明回调参数
ok点击确定时触发的回调函数选中值的对象列表
cancel点击取消时触发的回调函数event对象
change滚动时值变化时触发的回调函数选中值的对象列表