• Jobs
  • About Us
  • professionals
    • Home
    • Jobs
    • Courses and challenges
  • business
    • Home
    • Post vacancy
    • Our process
    • Pricing
    • Assessments
    • Payroll
    • Blog
    • Sales
    • Salary Calculator

0

310
Views
Trying to get my clock to work in bootstrapvue - what am I doing wrong?

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;
  }
};
about 3 years ago · Juan Pablo Isaza
1 answers
Answer question

0

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);
},
about 3 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Our process Sales
Legal
Terms and conditions Privacy policy
© 2025 PeakU Inc. All Rights Reserved.

Andres GPT

Recommend me some offers
I have an error