month-range.vue 1.6 KB

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