CardTime.vue 737 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. <template>
  2. <view class="card-time">{{ timeShow }}</view>
  3. </template>
  4. <script>
  5. import dayjs from 'dayjs'
  6. export default {
  7. props: {
  8. time: [String, Number]
  9. },
  10. computed: {
  11. timeShow() {
  12. const res = dayjs(this.time)
  13. const now = dayjs()
  14. if (now.format('YYYY年MM月DD日') === res.format('YYYY年MM月DD日')) {
  15. return res.format('HH:mm:ss')
  16. }
  17. if (
  18. now.subtract(1, 'day').format('YYYY年MM月DD日') ===
  19. res.format('YYYY年MM月DD日')
  20. ) {
  21. return '昨天 ' + res.format('HH:mm:ss')
  22. }
  23. return res.format('YYYY年MM月DD日 HH:mm:ss')
  24. }
  25. }
  26. }
  27. </script>
  28. <style scoped>
  29. .card-time {
  30. text-align: center;
  31. font-size: 28rpx;
  32. color: #aaaaaa;
  33. padding: 24rpx 0;
  34. }
  35. </style>