DataTime.vue 1018 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. <template>
  2. <div class="box">
  3. <p class="boxDate">{{ dateYear }}
  4. <br>
  5. <div class="boxTime"> {{ dateDay }}
  6. </div>
  7. </p>
  8. </div>
  9. </template>
  10. <script>
  11. import dayjs from "dayjs";
  12. export default {
  13. data() {
  14. return {
  15. dateDay: null,
  16. dateYear: null,
  17. dateWeek: null,
  18. weekday: ["星期日", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六"],
  19. timer: null,
  20. };
  21. },
  22. mounted() {
  23. this.timer = setInterval(() => {
  24. const date = dayjs(new Date());
  25. this.dateDay = date.format("HH:mm:ss");
  26. this.dateYear = date.format("YYYY-MM-DD");
  27. this.dateWeek = date.format(this.weekday[date.day()]);
  28. }, 1000);
  29. },
  30. beforeDestroy() {
  31. if (this.timer) {
  32. clearInterval(this.timer);
  33. }
  34. },
  35. };
  36. </script>
  37. <style scoped>
  38. .box {
  39. height: 100%;
  40. width: 100%;
  41. color: #fff;
  42. display: flex;
  43. align-items: center;
  44. }
  45. .boxDay {
  46. font-size: 16rem;
  47. }
  48. .boxTime {
  49. font-size: 18rem;
  50. margin: 0 16rem;
  51. }
  52. .boxDate {
  53. font-size: 12rem;
  54. }
  55. </style>