Home > Enterprise >  Trying to get my clock to work in bootstrapvue - what am I doing wrong?
Trying to get my clock to work in bootstrapvue - what am I doing wrong?

Time:10-29

Hey guys these are my codes trying to get my clock to work in bootstrap vue. I want the time to show real time with the seconds moving. Dates work, and time works, but time is stationary. What am i doing wrong? Newbie..#thanks

    <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;
  }
};

CodePudding user response:

You can just use setTimeout with 1000ms time interval with this.nowclock call back function

Codesandbox Demo

nowclock() {
  this.timeclock =  " "   new Date(Date.now()).toLocaleTimeString("en-US");
  if (!this.stopClock) setTimeout(this.nowclock, 1000);
},
  • Related