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

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

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 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