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

306
Views
¿Cómo puedo esperar a que el niño ejecute una función y realice un $emit para resolver una promesa?

Tengo un botón que cambia un accesorio que le estoy pasando a un niño.

En el niño estoy observando cambios en esta propiedad y realizaré una función para validar algunos campos. Después estoy usando $emit para cambiar el estado de una variable en mi padre.

Intenté devolver una nueva Promesa con una función while interna que sigue buscando un valor booleano cada 250 ms:

 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() } }) }...

Y luego en la llamada del niño:

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

Y el reloj:

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

El método del niño:

 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() } }) }) },

Quiero detener el while en el padre cuando this.waiting cambia a false. Entonces puedo realizar el if para resolver o rechazar:

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

Este es un botón siguiente que permitirá al usuario avanzar a la siguiente parte del formulario del asistente.

Estoy obteniendo un bucle infinito.

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