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

173
Views
Multiple instances of same vuejs component (popover) show same data on click

I am trying to show an AJAX response in a popover displayed by an icon (a custom Vue component which I wrote) when it is clicked. There are multiple instances of this component, which are rendered dynamically using the v-for directive in a table:

ParentComponent.vue

...
<tr v-for="(table, index) in tables" :key="index">
            <th scope="row">{{ index + 1 }}</th>
            <td scope="row">
              {{ table }}
            </td>
            <th scope="row">
              <Popover :popoverData="popoverData" @on-click="previewTable(table)" />
</tr> 
...
async previewTable(table) {
      
      const response = await axios.get(RestApi + `/${table}`);
      this.popoverData = response.data;
    }

Popover.vue

<template>
  <button class="btn" ref="button" aria-describedby="tooltip" @click='this.$emit("onClick")'>
    <i class="fa-solid fa-magnifying-glass"></i>
  </button>
  <div id="tooltip" ref="tooltip" role="tooltip">
    {{ popoverData }}
  </div>
</template>

<script>
import { createPopper } from "@popperjs/core";

export default {
  data() {
    return {};
  },
  props: { popoverData: String },
  mounted: ...

The problem is that when I click on one of these components ( which should show a popover with text coming fron an API call) and then I click on a second one without closing the first, the data looks like shared and not uniquely assigned to that specific instance of the component. I am also attaching an image to express things in clearer way (the API response is here replaced by table name) . As an example, the API response is replaced by table name Thanks for the support.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

As I mentioned in the comment, you pass the exact same popoverData prop to each Popover. To fix this, you probably can store distinct values for each popover in an object, using table (whatever it is) as a key:

ParentComponent script

data() {
  return {
    popovers: {},
    ...
  }
}
...
methods: {
  async previewTable(table) {
    const response = await axios.get(RestApi + `/${table}`);
    this.$set(this.popovers, table, response.data);
  }
  ...
}

ParentComponent template

<Popover :popoverData="popovers[table]" @on-click="previewTable(table)" />
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!