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

239
Views
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 answers
Answer question

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 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!