网站底部加上网站运行时间的教程

首先,在Vue组件的标签中添加一个用于显示运行时间的元素,例如:

<div>网站运行了: {{ days }}天{{ hours }}小时{{ minutes }}分{{ seconds }}秒</div>

然后,在Vue组件的标签中定义计算属性和生命周期钩子函数,如下所示:

<script>
export default {
data() {
return {
runtime: null,
days: 0,
hours: 0,
minutes: 0,
seconds: 0
};
},
mounted() {
this.showRuntime();
},
methods: {
showRuntime() {
setInterval(() => {
const startTime = new Date("3/27/2024 7:00:00"); //改为创立站点时间
const currentTime = new Date();
const timeDifference = currentTime.getTime() - startTime.getTime();
const millisecondsPerDay = 24 * 60 * 60 * 1000;
this.days = Math.floor(timeDifference / millisecondsPerDay);
this.hours = Math.floor((timeDifference % millisecondsPerDay) / (60 * 60 * 1000));
this.minutes = Math.floor((timeDifference % (60 * 60 * 1000)) / (60 * 1000));
this.seconds = Math.floor((timeDifference % (60 * 1000)) / 1000);
}, 1000);
}
}
};
</script>

版权声明:本文由 鹿泽笔记 原创发布。

本文链接:https://www.bailuze.com/6211.html

许可协议:本文标题《网站底部加上网站运行时间的教程》,转载请注明文章出处及原始链接。

鹿泽
鹿泽

深耕 SEO优化 十二年,从个人博客爱好者到专业谷歌优化顾问的成长之路。技术派SEO、全域流量技术运营专家,拥有多年从业经验,热衷于分析算法逻辑与推理的精准匹配。