Mixing dynamic and conditional class name in Vue 2

Viewed 875

Let's say I want a div with class a0 to a9 according to index in v-for and class b conditionally.

To do it separately, it looks like this:

<div v-for="(val, index) in array" :class="'a' + index"></div>

and

<div v-for="(val, index) in array" :class="{'b': index===1}"></div>

When we mix them together, given that this does not work:

<div v-for="(val, index) in array" :class="{'a' + index: true, 'b': index===1}"></div>

and the best (working solution) I can get is this:

<div v-for="(val, index) in array" :class="'a' + index + ' ' + (index===1?'b':'') }"></div>

Are there any better ways? Thanks.

1 Answers
Related