M
M
Mikhail Smirnov2020-09-30 17:08:13
Vue.js
Mikhail Smirnov, 2020-09-30 17:08:13

How to add class in vuejs?

The item.icon property specifies the name of the icon, for example icon-tv, it needs to be added to the section__icon class to end up with class="section__icon icon-tv"

In the documentation, I found only the v-bind:class="{'class-name" option ': true}"
But how to apply it in my situation is not clear

<div class="sections-list" v-for="(item, i) in sections">

                        <div class="section">
                            <div class="section__icon"></div>
                            <div class="section__title">{item.title}</div>
                        </div>
                    </div>

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vladimir Borutkin, 2020-09-30
@fortoster82

everything is clearly described in the documentation in this regard

:class=['class1', iconTv]

computed : {
iconTv () {
return "iconTv"}
}

https://ru.vuejs.org/v2/guide/class-and-style.html
describes how to conditionally add a class

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question