date-and-time-range.vue 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. <template>
  2. <div class="block">
  3. <span class="demonstration">Default</span>
  4. <el-date-picker
  5. v-model="value1"
  6. type="datetimerange"
  7. range-separator="To"
  8. start-placeholder="Start date"
  9. end-placeholder="End date"
  10. />
  11. </div>
  12. <div class="block">
  13. <span class="demonstration">With shortcuts</span>
  14. <el-date-picker
  15. v-model="value2"
  16. type="datetimerange"
  17. :shortcuts="shortcuts"
  18. range-separator="To"
  19. start-placeholder="Start date"
  20. end-placeholder="End date"
  21. />
  22. </div>
  23. </template>
  24. <script lang="ts" setup>
  25. import { ref } from 'vue'
  26. const value1 = ref<[Date, Date]>([
  27. new Date(2000, 10, 10, 10, 10),
  28. new Date(2000, 10, 11, 10, 10),
  29. ])
  30. const value2 = ref('')
  31. const shortcuts = [
  32. {
  33. text: 'Last week',
  34. value: () => {
  35. const end = new Date()
  36. const start = new Date()
  37. start.setTime(start.getTime() - 3600 * 1000 * 24 * 7)
  38. return [start, end]
  39. },
  40. },
  41. {
  42. text: 'Last month',
  43. value: () => {
  44. const end = new Date()
  45. const start = new Date()
  46. start.setTime(start.getTime() - 3600 * 1000 * 24 * 30)
  47. return [start, end]
  48. },
  49. },
  50. {
  51. text: 'Last 3 months',
  52. value: () => {
  53. const end = new Date()
  54. const start = new Date()
  55. start.setTime(start.getTime() - 3600 * 1000 * 24 * 90)
  56. return [start, end]
  57. },
  58. },
  59. ]
  60. </script>
  61. <style scoped>
  62. .block {
  63. padding: 30px 0;
  64. text-align: center;
  65. border-right: solid 1px var(--el-border-color);
  66. flex: 1;
  67. }
  68. .block:last-child {
  69. border-right: none;
  70. }
  71. .block .demonstration {
  72. display: block;
  73. color: var(--el-text-color-secondary);
  74. font-size: 14px;
  75. margin-bottom: 20px;
  76. }
  77. </style>