From 1c6fab0158ba9d48a19115b585ef54c7fdf5a04c Mon Sep 17 00:00:00 2001 From: alexm Date: Mon, 17 Jun 2024 09:53:36 +0200 Subject: [PATCH] fix(VnTable): duplicate fetch --- src/components/ui/VnPaginate.vue | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/components/ui/VnPaginate.vue b/src/components/ui/VnPaginate.vue index 625f8b845..b59f01835 100644 --- a/src/components/ui/VnPaginate.vue +++ b/src/components/ui/VnPaginate.vue @@ -70,6 +70,7 @@ const props = defineProps({ const emit = defineEmits(['onFetch', 'onPaginate', 'onChange']); const isLoading = ref(false); +const mounted = ref(false); const pagination = ref({ sortBy: props.order, rowsPerPage: props.limit, @@ -89,8 +90,9 @@ const arrayData = useArrayData(props.dataKey, { }); const store = arrayData.store; -onMounted(() => { - if (props.autoLoad) fetch(); +onMounted(async () => { + if (props.autoLoad) await fetch(); + mounted.value = true; }); watch( @@ -102,7 +104,10 @@ watch( watch( () => store.data, - (data) => emit('onChange', data) + (data) => { + console.log('EMIT CHANGE DATA'); + emit('onChange', data); + } ); watch( @@ -155,7 +160,7 @@ function endPagination() { emit('onPaginate'); } async function onLoad(index, done) { - if (!store.data) return done(); + if (!store.data || !mounted.value) return done(); if (store.data.length === 0 || !props.url) return done(false);