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

64
Vistas
How to set a different state's variable for each children inside loop Vue

I have the following problem with state usage on below code snippet.

<div class="featured-card-container">
  <swiper class="swiper" :options="swiperOption">
    <template v-for="(strategy, index) in strategiesCards">
      <swiper-slide :key="'slider-' + index">
        <strategy-card
          :data="strategy"
          @click.native="showModalStrategies()"
        />
      </swiper-slide>
      <strategies-modal
        :key="'modal-' + index"
        :dialog.sync="modalStrategies"
        :data="strategy"
      />
    </template>
    <div class="swiper-pagination" slot="pagination"></div>
  </swiper>
</div>

So basically, all I need to is triggering a modal from its responsible card. I just kind of having a hard time how to settle this. My current approach is the above code.

But I know the problem would come that, the modalStrategies data state is being used by many components. So it makes them like quickly changing all the existing modal even I clicked only one card.

How I can I fixed this? Is there any workaround?

Thank you so much everyone. I really appreciate your effort to try understanding my problems.

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

<template v-for="(strategy, index) in strategiesCards">
    <swiper-slide :key="'slider-' + index">
        <strategy-card
            :data="strategy"
            @click.native="showModalStrategies(strategy)"
        />
    </swiper-slide>
    <strategies-modal
        :key="'modal-' + index"
        :dialog.sync="isShowModal"
        :data="strategy"
    />
</template>
data() {
    return {
        modalStrategy: null,
        currentStrategy: null
    }
},
computed: {
    isShowModal: {
        get() {
            return this.modalStrategy === this.currentStrategy
        },
        // https://vuejs.org/v2/guide/components-custom-events.html#sync-Modifier
        set(val) {
            if(!val) {
                this.modalStrategy = null
            }
        }
    }
},
methods: {
    showModalStrategies(strategy) {
        this.currentStrategy= strategy
        this.modalStrategy = strategy
    }
}
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