Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

161
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!