0
0
Fork 0

perf: use FetchData instead VnPAginate

This commit is contained in:
Javier Segarra 2024-11-24 08:48:56 +01:00
parent 4fa5d47481
commit 8d59cfa9c3
1 changed files with 13 additions and 19 deletions

View File

@ -2,7 +2,7 @@
import { onBeforeMount, ref, watch } from 'vue'; import { onBeforeMount, ref, watch } from 'vue';
import { useI18n } from 'vue-i18n'; import { useI18n } from 'vue-i18n';
import { useRoute, useRouter } from 'vue-router'; import { useRoute, useRouter } from 'vue-router';
import VnPaginate from 'src/components/ui/VnPaginate.vue'; import FetchData from 'components/FetchData.vue';
import axios from 'axios'; import axios from 'axios';
@ -53,7 +53,6 @@ const addressFilter = {
onBeforeMount(() => { onBeforeMount(() => {
const { id } = route.params; const { id } = route.params;
// getAddressesData(id);
getClientData(id); getClientData(id);
}); });
@ -61,14 +60,9 @@ watch(
() => route.params.id, () => route.params.id,
(newValue) => { (newValue) => {
if (!newValue) return; if (!newValue) return;
// getAddressesData(newValue);
getClientData(newValue); getClientData(newValue);
} }
); );
async function onFetch(data) {
addresses.value = data;
sortAddresses();
}
const getClientData = async (id) => { const getClientData = async (id) => {
try { try {
@ -94,9 +88,9 @@ const setDefault = (address) => {
}); });
}; };
const sortAddresses = () => { const sortAddresses = (data) => {
if (!client.value || !addresses.value) return; if (!client.value || !data) return;
addresses.value = addresses.value.sort((a, b) => { addresses.value = data.sort((a, b) => {
return isDefaultAddress(b) - isDefaultAddress(a); return isDefaultAddress(b) - isDefaultAddress(a);
}); });
}; };
@ -117,17 +111,17 @@ const toCustomerAddressEdit = (addressId) => {
</script> </script>
<template> <template>
<FetchData
@on-fetch="sortAddresses"
auto-load
data-key="CustomerAddresses"
order="id DESC"
ref="vnPaginateRef"
:filter="addressFilter"
:url="`Clients/${route.params.id}/addresses`"
/>
<div class="full-width flex justify-center"> <div class="full-width flex justify-center">
<QCard class="card-width q-pa-lg"> <QCard class="card-width q-pa-lg">
<VnPaginate
@on-fetch="onFetch"
auto-load
data-key="CustomerAddresses"
order="id DESC"
ref="vnPaginateRef"
:filter="addressFilter"
:url="`Clients/${route.params.id}/addresses`"
></VnPaginate>
<QCardSection> <QCardSection>
<div <div
v-for="(item, index) in addresses" v-for="(item, index) in addresses"