试图让我的时钟在 bootstrapvue 中工作——我做错了什么?
Trying to get my clock to work in bootstrapvue - what am I doing wrong?
大家好,这些是我的代码,试图让我的时钟在 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;
}
};
大家好,这些是我的代码,试图让我的时钟在 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;
}
};