L
L
lacront2018-09-09 07:35:11
Vue.js
lacront, 2018-09-09 07:35:11

Dynamic class change in vue component?

Is it possible to dynamically change a class in a vue component? There is vue:

new Vue({
      el:'.container',
      data:{
        areas: new Array(24),
      }
    })

Component:
Vue.component('photos',{
      template:'#template-areas',
      props:['index'],
    })

I pass the array index to the component:
v-for="(item, index) in areas"
      :key="index"
      :index="index+1"

It is necessary that, depending on the current index, the template class changes, i.e. something like this:
template id="template-areas"
      div class=area{{index}}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Maria Lonshakova, 2018-09-09
@lacront

Documentation: https://ru.vuejs.org/v2/guide/class-and-style.html
Just addv-bind:class="'area' + index"

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question