demo6.vue 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. <template>
  2. <m-date-picker
  3. v-model="value1"
  4. placeholder="请选择日期"
  5. :shortcuts="shortcuts1">
  6. </m-date-picker>
  7. <m-date-picker
  8. class="date"
  9. v-model="value2"
  10. type="daterange"
  11. placeholder="请选择日期"
  12. :shortcuts="shortcuts2">
  13. </m-date-picker>
  14. </template>
  15. <script setup>
  16. import { ref } from 'vue-demi';
  17. const value1 = ref('');
  18. const value2 = ref([]);
  19. const shortcuts1 = [
  20. {
  21. text:'今天',
  22. value: () => {
  23. return new Date()
  24. }
  25. },
  26. {
  27. text: '昨天',
  28. value: () => {
  29. const date = new Date()
  30. date.setTime(date.getTime() - 3600 * 1000 * 24)
  31. return date
  32. }
  33. },
  34. {
  35. text: '一周前',
  36. value: () => {
  37. const date = new Date()
  38. date.setTime(date.getTime() - 3600 * 1000 * 24 * 7)
  39. return date
  40. }
  41. }
  42. ]
  43. const shortcuts2 = [
  44. {
  45. text: '最近一周',
  46. value: () => {
  47. const end = new Date()
  48. const start = new Date()
  49. start.setTime(start.getTime() - 3600 * 1000 * 24 * 7)
  50. return [start, end]
  51. }
  52. },
  53. {
  54. text: '最近一个月',
  55. value: () => {
  56. const end = new Date()
  57. const start = new Date()
  58. start.setTime(start.getTime() - 3600 * 1000 * 24 * 30)
  59. return [start, end]
  60. }
  61. },
  62. {
  63. text: '最近三个月',
  64. value: () => {
  65. const end = new Date()
  66. const start = new Date()
  67. start.setTime(start.getTime() - 3600 * 1000 * 24 * 90)
  68. return [start, end]
  69. }
  70. }
  71. ]
  72. </script>
  73. <style>
  74. .date{
  75. margin-left: 50px;
  76. }
  77. </style>