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

174
Vistas
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 Respuestas
Responde la pregunta

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