Skip to content

Commit 7cbb1ff

Browse files
author
ahmadhuss
committed
feat: Updated Front.vue file
1 parent 0567c0b commit 7cbb1ff

File tree

1 file changed

+15
-7
lines changed

1 file changed

+15
-7
lines changed

resources/js/components/Front.vue

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@
2525

2626
<div class="col-lg-9">
2727

28-
<div class="row my-5" v-if="Array.isArray(products) && products.length > 0">
29-
<div class="col-lg-4 col-md-6 mb-4" v-for="product in products">
28+
<div class="row my-5" v-if="Array.isArray(products.data) && products.data.length > 0">
29+
<div class="col-lg-4 col-md-6 mb-4" v-for="product in products.data">
3030
<div class="card h-100">
3131
<a :href="`/product/${product.name}`">
3232
<img class="card-img-top" src="http://placehold.it/700x400" alt="">
@@ -53,7 +53,14 @@
5353
</div>
5454
<!-- /.row -->
5555

56+
<!-- Vue pagination component we are binding data private property :data="products"
57+
and method named "loadProducts" -->
58+
<div class="d-flex align-items-center justify-content-center">
59+
<pagination :data="products" @pagination-change-page="loadProducts"></pagination>
60+
</div>
61+
5662
</div>
63+
5764
</template>
5865

5966

@@ -64,7 +71,7 @@ export default {
6471
data: function(){
6572
return {
6673
categories: [],
67-
products: [],
74+
products: {},
6875
loading: true
6976
}
7077
},
@@ -87,12 +94,13 @@ export default {
8794
}
8895
);
8996
},
90-
loadProducts: function (){
91-
axios.get('/api/products').then(response => {
92-
this.products = response.data.data;
97+
loadProducts: function (page = 1){
98+
axios.get(`/api/products?page=${page}`).then(response => {
99+
console.log(response.data);
100+
this.products = response.data;
93101
this.loading = false;
94102
}).catch(err => {
95-
console.log(err);
103+
console.log('API Promise rejected error :', err);
96104
});
97105
}
98106
}

0 commit comments

Comments
 (0)