Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

122
Views
Trigger a function if countdown reaches 0 - VueJS

I have created a countdown timer which decrease a number in the template perfectly, but now I need it to launch a function declared within methods after it reaches 0. I've tried to check if condition is met within methods but it doesn't launch anything when reaching 0.

Here is my index.vue

<template>
  <div>
    {{ timerCount }}
  </div>
</template>

<script>
export default {
  data(){
     return{
        timerCount: 60
     }
   },

  watch: {
    timerEnabled(value) {
      if (value) {
        setTimeout(() => {
         this.timerCount = this.timerCount - 1;
        }, 1000);
      }
    },
    timerCount: {
      handler(value) {
        if (value > 0 && this.timerEnabled) {
          setTimeout(() => {
            this.timerCount = this.timerCount - 1;
          }, 1000);
        }
      },
      immediate: true
    },
  },

  methods:{
    launchThis() {
       // I need this function to be launched if timerCount reaches 0
     }
  }
}
</script>

Any guidance to make it work will greatly appreciated.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

You can use something like this

<script>
export default {
  watch: {
    timerCount: {
      handler(value) {
        if (value > 0 && this.timerEnabled) {
          setTimeout(() => {
            this.timerCount = this.timerCount - 1;
          }, 1000);
        } else {
          this.launchThis() // run your function here
        }
      },
      immediate: true
    },
  },
}
</script>
about 4 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 Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!