标签:int time() art this his 开始 tin show code
让页面一开始就加载就显示时间。
解决隔1s后才显示时间这个问题
<div id="app">
{{Showtime}}
</div>
<script>
var vm = new Vue({
el: "#app",
data: {
Showtime: ","
},
created() {
// 让页面一开始就加载就显示时间。
//解决隔1s后才显示时间这个问题
let newtime = new Date();
let myHover = newtime.getHours();
let myMin = newtime.getMinutes();
this.Showtime = myHover + ":" + myMin;
// 让后每隔1s跟新时间
this.runTime();
},
methods: {
runTime() {
let clearTime = setInterval(() => {
let newtime = new Date();
let myHover = newtime.getHours();
let myMin = newtime.getMinutes();
this.Showtime = myHover + ":" + myMin;
this.runTime();
}, 1000)
}
},
})
</script>
标签:int time() art this his 开始 tin show code
原文地址:https://www.cnblogs.com/IwishIcould/p/12199125.html