92 lines
2.1 KiB
Vue
92 lines
2.1 KiB
Vue
<script setup>
|
|
import { onMounted, ref } from 'vue';
|
|
|
|
const props = defineProps({
|
|
total: {
|
|
type: Number,
|
|
required: true,
|
|
},
|
|
limit: {
|
|
type: Number,
|
|
default: 10
|
|
},
|
|
currentPage: {
|
|
type: Number,
|
|
default: 0
|
|
}
|
|
})
|
|
|
|
const emits = defineEmits(['get-elements'])
|
|
const currentPage = ref(0);
|
|
const totalPage = ref(0)
|
|
onMounted(() => {
|
|
currentPage.value = props.currentPage;
|
|
totalPage.value = Math.ceil(props.total / props.limit)
|
|
})
|
|
|
|
const setPage = (p) => {
|
|
console.log('Page:', p);
|
|
currentPage.value = p
|
|
const skip = (p - 1) * props.limit;
|
|
emits('get-elements', {skip: skip, page: p});
|
|
}
|
|
</script>
|
|
|
|
<template>
|
|
<div class="pagination" v-if="totalPage > 1">
|
|
<h4>Paginación</h4>
|
|
<div class="box-pages" v-if="totalPage > 1">
|
|
<div
|
|
v-for="p in totalPage"
|
|
:class="[currentPage === (p - 1) ? 'page page-active' : 'page']"
|
|
@click="setPage(p - 1)"
|
|
>
|
|
{{ p }}
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</template>
|
|
|
|
<style scoped>
|
|
.pagination {
|
|
display: flex;
|
|
flex-direction: column;
|
|
align-items: center;
|
|
justify-content: center;
|
|
margin-top: 2rem;
|
|
}
|
|
|
|
.pagination h4 {
|
|
font-size: 1.2rem;
|
|
font-weight: 900;
|
|
}
|
|
.box-pages {
|
|
/* left: 50%; */
|
|
display: flex;
|
|
/* flex-direction: column; */
|
|
justify-content: center;
|
|
}
|
|
|
|
.page {
|
|
cursor: pointer;
|
|
display: flex;
|
|
width: 30px;
|
|
height: 30px;
|
|
border-radius: 100%;
|
|
align-items: center;
|
|
justify-content: center;
|
|
align-content: center;
|
|
background-color: #dab977;
|
|
color: #323030;
|
|
margin: 4px;
|
|
font-size: 1.1rem;
|
|
font-weight: 500;
|
|
}
|
|
.page-active {
|
|
width: 33px;
|
|
height: 33px;
|
|
font-size: 1.2rem;
|
|
font-weight: 700;
|
|
background-color: #FBBA33;
|
|
}
|
|
</style> |