Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

123
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda