Answer the question
In order to leave comments, you need to log in
How to access a specific dom element in vue?
Hello.
There is such a code on js https://jsfiddle.net/2rpbqza0/ The bottom line is: there is an array with numbers. An element is created for each number. And there is a button, after clicking on which the elements change color in ascending order.
In this example, when creating an element, I add an id to it with an array value, by which I can later access it.
How to do the same on vue, working with data, and not with dom directly? https://jsfiddle.net/jg5u6f74/
Answer the question
In order to leave comments, you need to log in
.active {
background: red;
}
data: () => ({
val: -Infinity,
...
}),
methods: {
onClick() {
this.val = Math.min(...this.arr.filter(n => n > this.val));
},
...
},
<div v-for="n in arr" :class="{ active: n <= val }">{{ n }}</div>
<button @click="onClick">click me</button>
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question