I'm new to Vue and arrays and I need help paginating my json array so that only 10 items are displayed per page. Currently, all the items in the array are being shown in the <tr>
body. I've tried different methods without success. Can someone assist me in finding the best way to paginate this json array and have it reflected in my table? Thank you.
Here is the code:
https://codesandbox.io/s/exciting-kapitsa-8d46t?file=/src/App.vue:1415-2437
App.vue
<template>
<div id="app">
<table class="table t3">
<thead class="thead">
<tr class="tr">
<th class="td no" width="10%">
<span class="has-text-orange">No</span>
</th>
<th class="td">
<span class="has-text-orange">Name</span>
</th>
</tr>
</thead>
<tbody
class="searchable tbody"
style="max-height: 200px; min-height: 200px"
>
<tr class="tr" v-for="(p, index) in alphabets" :key="index">
<td class="td no" width="10%">{{ ++index }}</td>
<td class="td">{{ p.letter }}</td>
</tr>
</tbody>
</table>
<div class="column is-12">
<nav
class="pagination is-right"
role="navigation"
aria-label="pagination"
>
<ul class="pagination-list">
<li>
<a @click="prev"> Prev </a>
</li>
<li>
<span
class="pagination-link go-to has-text-orange"
aria-label="Goto page 1"
>{{ current }}</span
>
</li>
<li>
<a @click="next()"> Next </a>
</li>
<li>
<input type="text" class="pagination-link" />
</li>
<li>
<button class="button">Go</button>
</li>
</ul>
</nav>
</div>
</div>
</template>
<script>
export default {
name: "App",
components: {},
data() {
return {
current: 1,
alphabets: [
{ letter: "a" },
{ letter: "b" },
{ letter: "c" },
{ letter: "d" },
{ letter: "e" },
{ letter: "f" },
{ letter: "g" },
{ letter: "h" },
{ letter: "i" },
{ letter: "j" },
{ letter: "k" },
{ letter: "l" },
{ letter: "m" },
{ letter: "n" },
{ letter: "o" },
{ letter: "p" },
{ letter: "q" },
{ letter: "r" },
{ letter: "s" },
{ letter: "t" },
{ letter: "u" },
{ letter: "v" },
{ letter: "w" },
{ letter: "x" },
{ letter: "y" },
{ letter: "z" },
],
};
},
};
</script>
<style>
#app {
font-family: "Avenir", Helvetica, Arial, sans-serif;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
text-align: center;
color: #2c3e50;
margin-top: 60px;
}
</style>