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

254
Views
Vue rastrea el índice de preguntas en el formulario.

Tengo un componente 'formulario' que contiene 6 preguntas. Tengo un complemento para generar entrada de teléfono. La pregunta del teléfono es la tercera y necesito generarla solo cuando el número de pregunta es la tercera. Tengo un índice de preguntas en el gancho de data() , por lo que necesito llamar a la función generateTel() cuando el índice es 3 porque esta entrada se crea en DOM solo cuando el índice es 3.

El html se parece a:

 <div v-if="index === 1" class="question"></div> <div v-if="index === 2" class="question"></div> <div v-if="index === 3" class="question"></div> <div v-if="index === 4" class="question"></div> <div v-if="index === 5" class="question"></div> <div v-if="index === 6" class="question"></div>

¿Cómo puedo rastrear cuando el índice es igual a 3? ¿O tal vez no es la mejor práctica y no debería usar v-if?

Nota: la solución de Bergur funciona pero tuve que agregar algunas correcciones:

 watch: { index(newVal) { if (newVal === 3) { let ref = this // to avoid this.generateTel() is not a function error setTimeout(function () { // add setTimeout to avoid calling method on undefined ref.generateTel() }, 100) } } }
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Usar reloj: https://vuejs.org/v2/guide/computed.html#Watchers

En su componente:

 watch: { index(newVal) { if (newVal === 3) { this.generateTel() } } }
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!