Answer the question
In order to leave comments, you need to log in
How to iterate over each element and assign a class in this case?
I am splitting
a word by letter and it is necessary to add a class to each element (letter) one by one
As far as I understand, if I use then I cannot access the index, say in mounted? How then to be? Well, do not manually write an object with each letter and property in data. v-for="(word, index) in element.value.split('')"
Answer the question
In order to leave comments, you need to log in
Inside v-for, you can use the method that is an example as an argument to the index you need. And already inside the method you return the required class for the v-for loop element.
methods: {
setRandomClass(word, index) {
return some class here;
}
}
<div v-for="(word, index) in element.value.split('')" :class="[setRandomClass(word, index)]"></div
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question