date-and-time-range.vue 1.7 KB

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