Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

vue.js insert block for every 6th loop element

I have offers cards list rendering thru the loop. Every 3rd col (bootstrap) elements i add row div. Now i need to add another col element (banner block) for every 6th element. For render some thing like that:

enter image description here

How i can implement that?

My code now

<div class="row" v-for="i in Math.ceil(offers.length / 3)">
    <div class="col-xl-4 col-lg-4 col-md-6 col-sm-12 col-12" v-for="offer in offers.slice((i-1)*3, i*3)">
        <h2>{{offer.name}}</h2>
        <h2>{{offer.desc}}</h2>
    </div>
</div>
like image 352
Konstantin Rusanov Avatar asked Dec 08 '22 12:12

Konstantin Rusanov


1 Answers

for loop:

    <div class="mycol" v-for="(offer,ind) in offers">
      <template v-if="ind % 5 == 0">
       <h2>banner</banner>
      </template>
      <template v-else>
       <h2>{{offer.name}}</h2>
       <h2>{{offer.desc}}</h2>
      </template>
    </div>

for new line for every third col you can use css

.mycol:nth-child(3n+1){
 clear:left;
}
like image 164
patapity Avatar answered Dec 11 '22 07:12

patapity