0

I'm using Vue and Vue Bootsrap. I wrote the following code:

<b-card border-variant="primary" header="Results:" header-bg-variant="primary" header-text-variant="white" align="center">
    <div v-if="loading">
        <img width="50px" height="50px" src="/assets/img/loading.gif" />
    </div>
    <div v-else-if="tools.length">
        <div id="app" class="container">
            <div class="grid">
                <article v-for="tool in tools">
                    <div class="title">
                        <h3>{{capitalizeFirstLetter(tool.name)}}</h3>
                    </div>
                    <div class="description">
                        {{tool.description}}
                    </div>
                </article>
            </div>
        </div>
    </div>
</b-card>

I want to add pagination. Each page should contain up to 9 cards. In the docs it was suggested to add:

<div class="overflow-auto">
    <b-pagination
        v-model="currentPage"
        :total-rows="rows"
        :per-page="perPage"
        first-text="First"
        prev-text="Prev"
        next-text="Next"
        last-text="Last"
    ></b-pagination>
</div>

But how should I wrap the cards and show only 9?

vesii
  • 2,760
  • 4
  • 25
  • 71

1 Answers1

2

<article v-for="tool in tools.slice((currentPage-1)*perPage,(currentPage-1)*perPage+perPage)" :key=tool> just slice your array according to the current page

you can check out the fiddle here https://jsfiddle.net/allanbanis/La8b0k23/21/

PS: I'm not using 9 as perpage value because I copied and pasted only 9 unique entries[Silly me], so each page would look the same if i used 9

Allan Banis
  • 376
  • 4
  • 18
  • Thank you for your help. it looks like it does not keep the right amount of cards in the page. For example, in your fiddle, change the `perPage` to 6 and will still show more than that. – vesii Mar 07 '20 at 22:51
  • ohh sorry it was my faulty slicing logic please refer to the edited answer – Allan Banis Mar 07 '20 at 23:17