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

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

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