VueJS Loop remaining

Viewed 60

I have a little problem. I would like to create a loop to display my articles the problem is that. I want it to never be empty basically if I have 0 articles but. I want 10 this one will display 10 skeleton if I have 1 item this will remove 1 skeleton to replace it with my item.

1

I don't know if I was clear enough so here is a little picture. Basically I have 6 dark gray rectangles but if I have 1 item I would only have 5 if I have 6 I would have no dark gray rectangle at all.

2 Answers

I use

<transition-group name="fade" tag="div" class="badge__grid">
        <template v-for="(n, i) in badges.data">
          <div :key="n + i" class="badge__item">
            <img
              class="badge__item--picture"
              :src="
                'https://images.habbo.com/c_images/album1584/' +
                  n.badge_code +
                  '.gif'
              "
              :alt="n.badge_code"
            />
            <span class="badge__item--code">
              {{ n.badge_code }}
            </span>
          </div>
        </template>
        <div
          v-for="i in badges.remaining"
          :key="i"
          class="badge__item badge__item--empty"
        ></div>
      </transition-group>

It works but I find it too many and I can't simplify my code

Related