[Vuejs]-VUEjs how to make a banner appear every 3 elements

0👍

Here’s a suggestion:

   // elements is [1,2]
   <div v-for="(e, i) in elements" :key="i">
       <div></div>
       <div></div>
       <div></div>
       <Banner></Banner>
   <div>

Or you could do some conditional rendering based on the index so:

   // elements is [1,2,3,4,5,6,7,8]
   <div v-for="(e, i) in elements" :key="i">
      <Banner v-if="!((i + 1) % 4)" />
      <div v-else></div>
   <div>

Leave a comment