ClearBowl/front/components/Products/ProductsList.vue

73 lines
2.2 KiB
Vue
Raw Normal View History

2019-12-05 11:23:34 +01:00
<template>
<div>
2019-12-15 22:52:29 +01:00
<Table :columns="columns" :border="true" :data="data" :loading="loading"/>
2019-12-05 11:23:34 +01:00
<Page @on-change="retrieveProducts" :total="pagination.total" style="margin-top:10px;"/>
</div>
</template>
<script>
export default {
name: 'ProductsList',
mounted() {
this.retrieveProducts();
},
data() {
return {
columns: [
{
title: 'Nazwa',
key: 'name'
},
{
2019-12-09 17:25:25 +01:00
title: 'Kcal',
2019-12-05 11:23:34 +01:00
key: 'kcal'
},
{
2019-12-15 22:52:29 +01:00
title: 'Węglowodany (g)',
2019-12-05 11:23:34 +01:00
key: 'carbohydrates'
},
{
2019-12-15 22:52:29 +01:00
title: 'Białk (g)',
2019-12-05 11:23:34 +01:00
key: 'protein'
},
{
2019-12-15 22:52:29 +01:00
title: 'Tłuszcz (g)',
2019-12-05 11:23:34 +01:00
key: 'fat'
}
],
data: [],
pagination: {
total: 0
},
loading: true,
};
},
methods: {
retrieveProducts(page = 1) {
this.loading = true;
this.$axios.get('/product', {
params: {
page: page
}
})
.then((res) => {
let data = res.data.data.products;
let products = data.data;
let pagination = {
'current_page': data.current_page,
'per_page': data.per_page,
'total': data.total
};
this.data = products;
this.pagination = pagination;
this.loading = false;
})
.catch(() => {
this.loading = false;
this.$Message.error('Błąd!');
});
}
}
};
</script>