topimg.vue 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. <template>
  2. <div class="img">
  3. <img src="../../assets/images/tongfeng.png" alt="">
  4. <h1>通风系统</h1>
  5. <p>{{ nowTime }}</p>
  6. </div>
  7. </template>
  8. <script>
  9. export default {
  10. data() {
  11. return {
  12. src: '../../assets/images/tongfeng.png',
  13. nowTime:''
  14. }
  15. },
  16. mounted() {
  17. setInterval(this.getNowFormatDate, 1000);
  18. },
  19. beforeDestroy() {
  20. if(this.timeId){
  21. clearInterval(this.getNowFormatDate);
  22. }
  23. },
  24. methods: {
  25. getNowFormatDate() {
  26. var now = new Date();
  27. var year = now.getFullYear(); //获取年份
  28. var month = now.getMonth(); //获取月份
  29. var date = now.getDate(); //获取日期
  30. var day = now.getDay(); //获取星期
  31. var hour = now.getHours(); //获取小时
  32. var minute = now.getMinutes(); //获取分钟
  33. // if(minute.length<=1){
  34. // minute="0"+minute;
  35. // }
  36. // console.log(minute.length);
  37. var seconds =
  38. now.getSeconds() < 10 ? "0" + now.getSeconds() : now.getSeconds(); //获取秒
  39. month = month + 1;
  40. var arr_week = new Array(
  41. "星期日",
  42. "星期一",
  43. "星期二",
  44. "星期三",
  45. "星期四",
  46. "星期五",
  47. "星期六"
  48. );
  49. var week = arr_week[day];
  50. var time =
  51. year +
  52. "年" +
  53. month +
  54. "月" +
  55. date +
  56. "日 " +
  57. week +
  58. " " +
  59. hour +
  60. ":" +
  61. minute +
  62. ":" +
  63. seconds;
  64. this.nowTime= time;
  65. },
  66. },
  67. };
  68. </script>
  69. <style scoped>
  70. .img{
  71. height: 180px;
  72. position: relative;
  73. }
  74. img{
  75. width: 100%;
  76. height: 100%;
  77. }
  78. h1{
  79. color: #FFFFFF;
  80. position: absolute;
  81. top: 5px;
  82. left: 50%;
  83. transform: translate(-50%);
  84. text-shadow: 5px 5px 4px #0E0E0E;
  85. font-size: 30px;
  86. margin: 0;
  87. }
  88. p{
  89. position: absolute;
  90. right: 5px;
  91. /* left: 10px; */
  92. color: #FFFFFF;
  93. bottom: 0px;
  94. margin: 0px;
  95. }
  96. </style>