Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

175
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda