嘿伙計們,這些是我試圖讓我的時鐘在 bootstrap vue 中作業的代碼。我希望時間隨著秒的移動顯示實時。日期有效,時間有效,但時間是靜止的。我究竟做錯了什么?新手..#謝謝
<template>
<div>
<div>
{{timestring}}
</div>
<div>
{{timeclock}}
</div>
</div>
</template>
<script>
data ()=> ({
timeString: '',
timeclock: '',
stopClock: false}),
mounted () {
this.nowTime();
this.nowclock();
},
methods: {
nowTime () {
this.timeString = new Date(Date.now()).toLocaleDateString('en-US',
{ weekday: 'long', year: 'numeric', month: 'long', day: 'numeric' });
if (!this.stopClock) {
setTimeout(this.nowTime, 285);
}
},
nowclock () {
this.timeclock = ' ' new Date(Date.now()).toLocaleTimeString('en-US');
if (!this.stopClock) {
setTimeout(this.nowTime, 285);
}
}
},
beforeDestroy () {
this.stopClock = true;
}
};
uj5u.com熱心網友回復:
您可以使用setTimeout帶有回呼功能的1000ms時間間隔this.nowclock
nowclock() {
this.timeclock = " " new Date(Date.now()).toLocaleTimeString("en-US");
if (!this.stopClock) setTimeout(this.nowclock, 1000);
},
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/340825.html
上一篇:如何使用JQuery隱藏元素?
下一篇:查找標簽開始和結束之間的特定單詞
