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

161
Visualizações
Targeting the DOM element created with a v-for in Vue.Js

I have two nested v-for rendering for me a grid made out of n boxes (i.e 100 boxes). Every time the v-for render a box, it calls a function which should check if the x&y coordinates of the just created box are included in an array of randomly generated coordinates, if yes, it will push the reference to this DOM element into an array and/or it will manipulate the element somehow.

The problem is, that i can't find a way of targeting the rendered element, since there's no event to utilize for that purpose.

Code Example below:

<div v-for="x in 10" class=row">
    <div v-for="y in 10" class="box" :data-x="x" :data-y="y"> {{generateDOMB(x, y)}} </div>
</div>

data:

randomCoordinates = [
  {
    x: 8,
    y: 5
  },
  {
    x: 4,
    y: 2
  },
  {
    x: 5,
    y: 7
  },
];

DOMelements = [];

js:

function generateDOMB(x, y) {
    randomCoordinates.forEach(coordinate => {
        if (x == coordinate.x && y == coordinate.y) {
        DOMelements.push('THE DOM ELEMENT')}
    });
};

I tried using the $event parameter to the function, but it didn't worked, clearly, because no event has been triggered (if I call the same function on a "@click" attribute, it works perfectly).

I also tried using refs and id's but I didn't managed to achieve my goal.

Also looking on the VueJs docs I haven't found any way of doing it

As you probably already understood, I'm trying to do a kind of "minefield" clone for learning purpose :)

Thanks to everyone!

about 4 years ago · Juan Pablo Isaza
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