E
E
Erl2021-02-16 17:59:29
Vue.js
Erl, 2021-02-16 17:59:29

How to determine which element is in an array?

I have an Articles object and an array of ids
I render the Articles as

<articles v-for="article in articles">
  <span> {{article.id}} </span>
</articles>

in the ids array, there are just a few ids, and you need to somehow select those that matched, well, let’s say the hover class will return true or false to me, but I don’t understand how to carry out this check, it turns out I need to do it somehow at the render stage?
ids.includes('article.id')

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Anton Anton, 2021-02-16
@NooBiToo

<span :class="{'my-class': ids.includes(article.id)}"> {{article.id}} </span>

and a bunch of other ways , up to a loop not on articles, but on a computed property , which will already contain class names

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question