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

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