Skip to content

Instantly share code, notes, and snippets.

@jaouadballat
Created March 3, 2018 17:36
Show Gist options
  • Save jaouadballat/285ebb0c6b8aba28a448a37ff2a65e6d to your computer and use it in GitHub Desktop.
Save jaouadballat/285ebb0c6b8aba28a448a37ff2a65e6d to your computer and use it in GitHub Desktop.
<template>
<div>
<Cards :products="products" />
<p class="text-center mb-0">{{currentPage+1 }} / {{ pages }}</p>
<ul class="pagination justify-content-center">
<li class="page-item" :class="{disabled: prevUrl === ''}">
<button class="page-link" @click="checkPage(prevUrl)">Previous</button>
</li>
<li class="page-item" :class="{disabled: nextUrl === ''}">
<button class="page-link" @click="checkPage(nextUrl)">Next</button>
</li>
</ul>
</div>
</template>
<script>
import Cards from './Cards';
import Api from '@/config/Api'
export default {
components: {
Cards
},
data() {
return {
products: [],
currentPage: '',
pages: '',
prevUrl: '',
nextUrl: ''
}
},
created() {
Api().get('/products')
.then(response => {
this.products = response.data.products;
this.currentPage = response.data.currentPage;
this.pages = response.data.pages;
this.nextUrl = response.data.nextUrl;
this.prevUrl = response.data.prevUrl;
});
},
methods: {
checkPage(url) {
Api().get(url)
.then(response => {
this.products = response.data.products;
this.currentPage = response.data.currentPage;
this.pages = response.data.pages;
this.nextUrl = response.data.nextUrl;
this.prevUrl = response.data.prevUrl;
})
}
}
}
</script>
<style scoped>
</style>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment