Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

124
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda