datetime-picker.vue 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. <template>
  2. <view class="page container">
  3. <uni-card is-full>
  4. <text class="uni-h6">可以同时选择日期和时间的选择器</text>
  5. </uni-card>
  6. <uni-section :title="'日期用法:' + single" type="line"></uni-section>
  7. <view class="example-body">
  8. <uni-datetime-picker type="date" :clearIcon="false" v-model="single" @maskClick="maskClick" />
  9. </view>
  10. <uni-section :title="'日期时间用法:' + datetimesingle" type="line"></uni-section>
  11. <view class="example-body">
  12. <uni-datetime-picker type="datetime" v-model="datetimesingle" @change="changeLog" />
  13. </view>
  14. <uni-section :title="'日期范围用法:' + '[' + range + ']'" type="line"></uni-section>
  15. <view class="example-body">
  16. <uni-datetime-picker v-model="range" type="daterange" rangeSeparator="至" @maskClick="maskClick" />
  17. </view>
  18. <uni-section :title="'日期时间范围用法:' + '[' + datetimerange + ']' " type="line"></uni-section>
  19. <view class="example-body">
  20. <uni-datetime-picker v-model="datetimerange" type="datetimerange" rangeSeparator="至" />
  21. </view>
  22. <uni-section :title="'v-model用法:' + single" type="line"></uni-section>
  23. <view class="example-body">
  24. <uni-datetime-picker v-model="single" />
  25. </view>
  26. <uni-section :title="'时间戳用法:' + single" type="line"></uni-section>
  27. <view class="example-body">
  28. <uni-datetime-picker returnType="timestamp" v-model="single" @change="changeLog($event)" />
  29. </view>
  30. <uni-section :title="'date 对象用法:' + datetimesingle" type="line"></uni-section>
  31. <view class="example-body">
  32. <uni-datetime-picker type="datetime" returnType="date" v-model="datetimesingle" @change="changeLog" />
  33. </view>
  34. <uni-section :title="'插槽用法:' + single" type="line"></uni-section>
  35. <view class="example-body">
  36. <uni-datetime-picker v-model="single">我是一个插槽,点击我</uni-datetime-picker>
  37. </view>
  38. <uni-section :title="'无边框用法:' + single" type="line"></uni-section>
  39. <view class="example-body">
  40. <uni-datetime-picker v-model="single" :border="false" />
  41. </view>
  42. <uni-section :title="'disabled用法:' + single" type="line"></uni-section>
  43. <view class="example-body">
  44. <uni-datetime-picker v-model="single" disabled />
  45. </view>
  46. </view>
  47. </template>
  48. <script>
  49. export default {
  50. data() {
  51. return {
  52. single: '2021-5-3',
  53. datetimesingle: '2021-07-3',
  54. range: ['2021-02-1', '2021-3-28'],
  55. datetimerange: [],
  56. start: '2021-7-2',
  57. end: '2021-7-29'
  58. }
  59. },
  60. watch: {
  61. datetimesingle(newval) {
  62. console.log('单选:', this.datetimesingle);
  63. },
  64. range(newval) {
  65. console.log('范围选:', this.range);
  66. },
  67. datetimerange(newval) {
  68. console.log('范围选:', this.datetimerange);
  69. }
  70. },
  71. mounted() {
  72. setTimeout(() => {
  73. // this.datetimesingle = '2021-7-10'
  74. // this.single = '2021-2-12'
  75. // this.range = ['2021-03-1', '2021-4-28']
  76. // this.datetimerange = ["2021-07-08 0:00:00", "2021-08-08 23:59:59"]
  77. // this.start = '2021-07-10'
  78. // this.end = '2021-07-20'
  79. },3000)
  80. },
  81. methods:{
  82. change(e) {
  83. this.single = e
  84. console.log('----change事件:', this.single = e);
  85. },
  86. changeLog(e) {
  87. console.log('----change事件:', e);
  88. },
  89. maskClick(e){
  90. console.log('----maskClick事件:', e);
  91. }
  92. }
  93. }
  94. </script>
  95. <style lang="scss">
  96. .example-body {
  97. background-color: #fff;
  98. padding: 10px;
  99. }
  100. </style>