timeSever2.vue 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. <template>
  2. <view>
  3. <view style="display: flex;" @click="itemShow = true">{{itemData}}<u-icon name="arrow-down" style="margin-left: 17rpx;"></u-icon></view>
  4. <u-calendar
  5. title=""
  6. :show="itemShow"
  7. :defaultDate="defaultDateMultiple"
  8. mode="range"
  9. @confirm="confirm"
  10. :closeOnClickOverlay="true"
  11. @close='cancel'
  12. ></u-calendar>
  13. </u-calendar>
  14. </view>
  15. </template>
  16. <script>
  17. const d = new Date()
  18. const year = d.getFullYear()
  19. let month = d.getMonth() + 1
  20. month = month < 10 ? `0${month}` : month
  21. const date = d.getDate()
  22. let time = [`${year}-${month}-${date}`, `${year}-${month}-${date}`,]
  23. export default {
  24. data() {
  25. return {
  26. itemData: (`${year}-${month}-${date}` +' ~ ' + `${year}-${month}-${date}`), // 时间
  27. itemShow: false, // 时间选择器显隐
  28. defaultDateMultiple: time,
  29. }
  30. },
  31. methods: {
  32. confirm(e){
  33. console.log(e)
  34. this.itemData = e[0] + ' ~ ' + e[e.length -1]
  35. this.cancel()
  36. },
  37. // 关闭
  38. cancel(){
  39. this.itemShow = false
  40. },
  41. },
  42. }
  43. </script>
  44. <style lang="scss" scoped>
  45. .choice-left{
  46. float: left;
  47. overflow: hidden;
  48. display: flex;
  49. width: 250rpx;
  50. }
  51. </style>