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

236
Vistas
Action happening for all the items in v-for but I want to run the action on just the item I clicked on

I have an icon in the v-for loop and I want the action to be performed specifically to the one icon but it is happening for all the icons that are repeating because of v-for.

<template>
  <div>
    <tr
      v-for="(randomData, randomIndex) in obj['randomData']"
      :key="randomIndex"
      class="random-table"
    >
      <td data-label="Activity Alert">
        <el-popover
          v-model="remindMeVisibility"
          placement="left-start"
          width="500"
          trigger="manual"
          class="popover-form"
        >
          <RemindMe />
          <i
            slot="reference"
            class="el-icon-message-solid reminder-icon"
            @click="remindMeVisibility = true"
          ></i>
        </el-popover>
      </td>
    </tr>
  </div>
</template>

<script>
export default {
  data() {
    return {
      remindMeVisibility: false,
    }
  },
}
</script>
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

Here is a working example on how to have a specific popover edit per element for a given list.

<template>
  <div>
    <pre>{{ cityNames }}</pre>

    <section>
      <div v-for="city in cityNames" :key="city.id">
        <span>City {{ city.name }}</span>
        <el-popover v-model="city.popoverOpen" placement="top" width="160" class="popover">
          <el-button slot="reference">Update visibility</el-button>
          <p>Change the visibility of the City?</p>
          <div style="text-align: right; margin: 0">
            <el-button size="mini" type="text" @click="toggleCityVisibility({ id: city.id, visibility: false })">
              Hide it
            </el-button>
            <el-button type="primary" size="mini" @click="toggleCityVisibility({ id: city.id, visibility: true })">
              Make visible
            </el-button>
          </div>
        </el-popover>
      </div>
    </section>
  </div>
</template>

<script>
export default {
  data() {
    return {
      cityNames: [
        {
          id: 1,
          name: 'beijing',
          remindMeVisibility: false,
          popoverOpen: false,
        },
        {
          id: 2,
          name: 'shanghai',
          remindMeVisibility: false,
          popoverOpen: false,
        },
        {
          id: 3,
          name: 'guangzhou',
          remindMeVisibility: false,
          popoverOpen: false,
        }
      ]
    };
  },
  methods: {
    toggleCityVisibility({ id, visibility }) {
      console.log('id', id, 'visibility', visibility)
      this.targetedCity = this.cityNames.find(city => city.id === id)
      this.targetedCity.remindMeVisibility = visibility
    }
  },
}
</script>

<style scoped>
.popover {
  margin-left: 1rem;
}
</style>

Here, we do have a list of cities, and we want to toggle their visibility (remindMeVisibility).
The id in the list was given for the :key uniqueness + find it later on when editing the visibility of it.
I didn't expected popoverOpen to be required here, but it is (a global popover state is not feasible from what I've tried).

This is how it looks

enter image description here

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