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

162
Visualizações
vue function does not run after mounted()

A memory-game I am creating, I would like to start immediately after the page is loaded.

To start I need to createDeck() and showCards()

I tried several things in the export default {} like:

   created(){
     this.createDeck(),
     this.createShowCards()
   },

and

    mounted() {
      this.fetchCards(),    // also need to fetch the cards, this works ok...
      this.createDeck(),
      this.createShowCards()
      console.log('component mounted')
    },

I can get the game working when calling the startfunctions with a start button:

 <div class="text-center">
   <button  @click="startGame()" v-if="Object.keys(cards).length != 0">Start game</button>
 </div>

Can anyone explain to me what I am missing? How can I get the "button to be clicked automatically" ?

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

Try to wait cards to load:

async mounted() {
  await this.fetchCards()
  this.createDeck()
  this.createShowCards()    
},

and maybe you need to make that function async like

async fetchCards() { await ...}
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