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

223
Views
How to wait for async emits in Vue 3?

I'm triggering a submit event from a parent component, which emits an image data-url and a body text from two child components to the parent:

<ImgUploadComponent :triggerEmit="state.submit" @emitImage="getImage"/>
  
<EditorComponent :triggerEmit="state.submit" @emitBody="getBody"/>

The image and body are fetched with these functions:

const getImage = async (image) => {
    form.image = await image
    // arrives after storeRecord
}

const getBody = async (body) => {
    form.body = await body
    // arrives before storeRecord
}

and sent to the database in this function:

const storeRecord = async () => {
    state.submit = true
    await getImage
    await getBody
    console.log(form.image) // returns undefined
    form.post('/admin/posts')
}

Problem is that the body arrives before form.post is sent but the image arrives after. When I wrote this function, it used to work but now it doesn't and I can't figure out why. How do you do it right?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Thanks to @Estus' suggestion, I was able to use a watcher to solve my problem:

const storeRecord = () => {
    state.submit = true
    watch(() => form.image, () => {
        form.post('/admin/kreationen')
    })
}

const getImage = (image) => {
    form.image = image
}

const getBody = (body) => {
    form.body = body
}
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!