vue系统-实现右上角时间实时更新-parseTime

该代码段展示了一个Vue.js组件,用于在页面上实时显示日期和时间,包括年月日、星期和时分秒。它使用了自定义的`parseTime`函数来格式化时间,并通过设置定时器每秒更新时间信息。

在这里插入图片描述

<template>
  <div
    style="font-family: Roboto-Bold, Roboto; font-weight: bold; color: #1977c4;text-align:right;width: 100%;"
  >
    <span>{{ timeInfo.ymd }}</span>
    <span>{{ timeInfo.week }}</span>
    <span>{{ timeInfo.time }}</span>
  </div>
</template>
  
  <script>
import { parseTime } from "@/utils";
export default {
  components: {},
  props: {},
  data() {
    return {
      timeInfo: {
        ymd: "",
        week: "",
        time: "",
      },
    };
  },
  computed: {},
  watch: {},
  created() {},
  mounted() {
    this.initTime();
  },
  methods: {
    initTime() {
      clearInterval(this.$el.initTimer);
      //let timer = setInterval(() => {
      //  this.timeInfo.ymd = parseTime(new Date(), "{yy}-{mm}-{dd}");
      //  this.timeInfo.week = parseTime(new Date(), "星期{a}");
      //  this.timeInfo.time = parseTime(new Date(), "{hh}:{ii}:{ss}");
      //});
      //火狐33
      let timer = setInterval(() => {
        this.timeInfo.ymd = parseTime(new Date(), "{yy}-{mm}-{dd}");
        this.timeInfo.week = parseTime(new Date(), "星期{a}");
        this.timeInfo.time = parseTime(new Date(), "{hh}:{ii}:{ss}");
      },1000);
      this.$el.initTimer = timer;
    },
  },
};
</script>
  <style scoped lang='scss'>
</style>
  
<timeInfo class="timeInfo"></timeInfo>
import timeInfo from "./components/timeInfo.vue";

components: {  timeInfo },
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值