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

273
Visualizações
Why is Vue warning me about infinite loop?

Vue is warning me the following message:

You may have an infinite update loop in a component render function

What I found out is that I should use computed and not methods, but it didn't work for me. What is causing this problem? Everything is working, there's no infinite loop happening, but Vue is still warning me.

.battle__invite(v-for='(invite, index) in invites', :key='index')
  battle__result.battle__result--finished(         
      :class='getResultClass(invite.challengerScore, invite.challengedScore)'
    ) {{ challengeResult }}

Computed:

getResultClass() {
      return (challengerScore, challengedScore) => {
        if (challengerScore > challengedScore) {
          this.challengeResult = 'win'
          return 'win'
        } else if (challengerScore < challengedScore) {
          this.challengeResult = 'defeat'
          return 'defeat'
        } else {
          this.challengeResult = 'draw'
          return 'draw'
        }
      }
    },
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

It's because of challengeResult variable. You use this in both template and computed property and this causes infinity re-render.

If you write a console.log("im in computed property") and put it in getResultClass, you get about 200 console.log which shows the infinity re-rendering bug. But vue doesn't allow to do infinity re-rendering and stop it (what a great framework!)

The reason is simple! In template you use getResultClass. In this computed you change challengeResult variable. Then because you use challengeResult in template section, It causes another re-rendering and the computed property runs again. And this loop goes forever!

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