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

185
Vistas
¿Cómo mostrar elementos dentro de v-for paso a paso al hacer clic?

Tengo una matriz con datos. Por defecto, solo el primer elemento debe ser visible.

Al hacer clic en el botón SÍ o NO, necesito mostrar el elemento cuya identificación corresponde a sí_sección o no_sección (según el botón en el que se hizo clic)

Por ejemplo, si en el bloque Ejemplo 1 hacemos clic en el botón "no 4", entonces el bloque Ejemplo 4 aparece debajo, y si hacemos clic en "sí 2", entonces debería aparecer el bloque Ejemplo 2.

¡Gracias por adelantado! =)

 new Vue({ el: "#app", data:{ stepsData: [ { id: "1", yes_section: "2", no_section: "4", name: "Example 1" }, { id: "2", yes_section: "5", no_section: "3", name: "Example 2" }, { id: "3", yes_section: "2", no_section: "4", name: "Example 3" }, { id: "4", yes_section: "2", no_section: "4", name: "Example 4" }, { id: "5", yes_section: "2", no_section: "4", name: "Example 5" }, ] } });
 .step { background: #ccc; padding: 20px; margin-bottom: 15px; }
 <script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.5.17/vue.js"></script> <div id="app"> <div v-for="(step, id) in stepsData" :key="step.id" class="step" > <div class="legal-aid__step-question" v-html="step.name"></div> <button>YES {{ step.yes_section }}</button> <button>NO {{ step.no_section }}</button> </div> </div>

over 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

Debe guardar step_id y usar propiedades calculadas ( https://vuejs.org/v2/guide/computed.html ) para mostrar la información del paso necesario

 new Vue({ el: "#app", data: () => ({ active_step_id: "1", stepsData: [ { id: "1", yes_section: "2", no_section: "4", name: "Example 1" }, { id: "2", yes_section: "5", no_section: "3", name: "Example 2" }, { id: "3", yes_section: "2", no_section: "4", name: "Example 3" }, { id: "4", yes_section: "2", no_section: "4", name: "Example 4" }, { id: "5", yes_section: "2", no_section: "4", name: "Example 5" }, ] }), computed: { active_step() { return this.stepsData.find(step => step.id === this.active_step_id) } } });
 .step { background: #ccc; padding: 20px; margin-bottom: 15px; }
 <script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.5.17/vue.js"></script> <div id="app"> <div class="step" > <div class="legal-aid__step-question" v-html="active_step.name"></div> <button @click.prevent="active_step_id = active_step.yes_section">YES {{ active_step.yes_section }}</button> <button @click.prevent="active_step_id = active_step.no_section">NO {{ active_step.no_section }}</button> </div> </div>

over 4 years ago · Santiago Trujillo 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