I am trying to create a pagination feature to display html blocks in increments of 2 and then a user can choose a page. The amount of blocks it'll go through is defined by a v-for. Here's the block of code to show this
<template v-for="(ad, index) in ads" v-cloak>
<div class="box ad-box" v-if="showAds(index)" @click="hideInput(index)">
<span> {{ lines(index, 'headline1') }} | </span>
<span> {{ lines(index, 'headline2') }} | </span>
<span> {{ lines(index, 'headline3') }} </span>
<span class="icon is-pulled-right has-text-grey-light has-text-weight-light" @click="deleteAd()">
<div v-show="ad.boolean">
<p class="">X</p>
</div>
</span>
<br>
<p><span class="is-size-7">{{lines(index, 'finalurl')}}</span><span class="is-size-7 has-text-success" v-if="lines(index, 'path1') !== '' ">/{{lines(index, 'path1')}}/{{lines(index,'path2')}}</span></p>
<span class="is-size-7 is-grey">{{lines(index, 'desc1') + lines(index, 'desc2')}} </span>
</div>
<br />
</template>
<nav class="pagination" role="navigation" aria-label="pagination">
<ul class="pagination-list">
<li>
<a class="pagination-link is-current">1</a>
</li>
<li v-show="ads.length > 2">
<a class="pagination-link" @click="adPage = 2">2</a>
</li>
<li v-show="ads.length > 4">
<a class="pagination-link" @click="adPage = 3">3</a>
</li>
<li v-show="ads.length > 6">
<a class="pagination-link" @click="adPage = 4">4</a>
</li>
<li v-show="ads.length > 8">
<a class="pagination-link" @click="adPage = 5">5</a>
</li>
</ul>
</nav>
I've got adPage in the data property to keep track of when a user clicks on a page and the page numbers will only appear as the proper amount of templates is actually available. I've got simple logic in a function but not really sure where to go from here. I was thinking I would check the index of what's being iterated and check it to be within a delta of 2 from what ever that adPage is.
newAds:[
[
{
id: 0,
headline1: 'first 1',
headline2: 'Headline 2',
headline3: 'headline3',
desc1: 'This is your description 1',
desc2: 'This is your description 2',
finalurl: 'www.finalURL.com',
path1: '',
path2: '',
boolean: true
},
{
id: 0,
headline1: 'first 2',
headline2: 'Headline 2',
headline3: 'headline3',
desc1: 'This is your description 1',
desc2: 'This is your description 2',
finalurl: 'www.finalURL.com',
path1: '',
path2: '',
boolean: false
}
],
[
{
id: 1,
headline1: 'second 1',
headline2: 'Headline 2',
headline3: 'headline3',
desc1: 'This is your description 1',
desc2: 'This is your description 2',
finalurl: 'www.finalURL.com',
path1: '',
path2: '',
boolean: false
},
{
id: 1,
headline1: 'second 2',
headline2: 'Headline 2',
headline3: 'headline3',
desc1: 'This is your description 1',
desc2: 'This is your description 2',
finalurl: 'www.finalURL.com',
path1: '',
path2: '',
boolean: false
}
]
]
sliceof ads that go on the current page, andv-forover that. For your page list, dov-for="p in Math.ceil(ads.length / 2)"