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

317
Vistas
How can I wait for the child to execute a function and perform an $emit to resolve a promise?

I have a button that changes a prop that I am passing to a child.

In the child I am watching for changes in this property and will perform a function to validate some fields. After it I am using $emit to change the state of a variable in my parent.

I tried to return a new Promise with a while function inside that keeps checking for a boolean value every 250ms:

methods: {
endPersonalTabValidation(x) {
  this.waiting= false
  this.accountValidated = x
},
startPersonalTabValidation() {
  this.keyPersonalTab = String(Math.floor(Math.random() * 10))

  this.waiting = true

  return new Promise((resolve, reject) => {
    do {
      setTimeout(() => {
        console.log('Waiting...')
      }, 250)
    } while (this.waiting)

    if (this.accountValidated) {
      resolve(true)
    } else {
      reject()
    }
  })
}...

And then in the child call:

<personal-tab
    :validate-tab="keyPersonalTab"
    @clicked="endPersonalTabValidation"
        />

And the watch:

watch: {
    validateTab(newVal, oldVal) {
      this.validationForm()
      console.log(newVal, oldVal)
    },
  },

The child method:

validationForm() {
  return new Promise((resolve, reject) => {
    this.$refs.validatePersonal.validate().then(success => {
      if (success) {
        this.$emit('clicked', true)
        resolve(true)
      } else {
        this.$emit('clicked', false)
        reject()
      }
    })
  })
},

I want to stop the while in the parent when this.waiting changes to false. Then I can perform the if to resolve or reject:

if (this.accountValidated) {
  resolve(true)
} else {
  reject()
}

This is a next button that will allow the user to advance to the next part of the wizard form.

I am getting a infinite loop.

about 4 years ago · Juan Pablo Isaza
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