M
M
marsdenden2018-09-10 15:32:55
JavaScript
marsdenden, 2018-09-10 15:32:55

How to form a class in a loop by condition in vue?

It is necessary in the loop for elements for which a certain condition is met (in this case, for elements from the 3rd to the end) to form a class, that is, I want something like the following, but this option does not work, swears at an unexpected token +

<div v-for="(t1,i1) in array1">
  <div v-for="(t2,i2) in array2">
    <div :class="{'cls'+'_'+i1:i2>2}">{{t2}}</div>
  </div>        
</div>

i.e. you need to get the following
<div>
  <div>
    <div>aa</div>
  </div>
  <div>
    <div>bb</div>
  </div>
  <div>
    <div class="cls_0">cc</div>
  </div>
  <div>
    <div class="cls_0">dd</div>
  </div>
</div>
<div>
  <div>
    <div>aaa</div>
  </div>
  <div>
    <div>bbb</div>
  </div>
  <div>
    <div class="cls_1">ccc</div>
  </div>
  <div>
    <div class="cls_1">ddc</div>
  </div>
</div>


I can't figure out how to do it?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
0
0xD34F, 2018-09-10
@marsdenden

:class="{ ['cls_'+ i1]: i2 > 2 }"
I recommend to take a look .

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question