S
S
scondic2020-01-19 16:20:42
Vue.js
scondic, 2020-01-19 16:20:42

How to assign different classes to elements of the same type, depending on the number?

I have a component that stores data, which in turn stores post objects. Posts have a number of stars (key: value). I need to make it so that depending on the value, the number of stars is displayed.
Let's say 4 stars, then it is displayed (fas classes are shaded, and far are not shaded):

<i class="fas fa-star"/>
<i class="fas fa-star"/>
<i class="fas fa-star"/>
<i class="fas fa-star"/>
<i class="far fa-star"/>

Answer the question

In order to leave comments, you need to log in

1 answer(s)
0
0xD34F, 2020-01-19
@scondic

<i v-for="i in 5" :class="[ i <= stars ? 'fas' : 'far', 'fa-star' ]" />

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question