fix: simplify data fetching logic in VnCard.vue #1656
|
@ -26,11 +26,7 @@ const route = useRoute();
|
||||||
const stateStore = useStateStore();
|
const stateStore = useStateStore();
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
const entityId = computed(() => props.id || route?.params?.id);
|
const entityId = computed(() => props.id || route?.params?.id);
|
||||||
const arrayData = useArrayData(props.dataKey, {
|
let arrayData = getArrayData(entityId.value, props.url);
|
||||||
url: props.url,
|
|
||||||
userFilter: props.filter,
|
|
||||||
oneRecord: true,
|
|
||||||
});
|
|
||||||
|
|
||||||
onBeforeRouteLeave(() => {
|
onBeforeRouteLeave(() => {
|
||||||
stateStore.cardDescriptorChangeValue(null);
|
stateStore.cardDescriptorChangeValue(null);
|
||||||
|
@ -61,16 +57,31 @@ onBeforeRouteUpdate(async (to, from) => {
|
||||||
});
|
});
|
||||||
|
|
||||||
async function fetch(id, append = false) {
|
async function fetch(id, append = false) {
|
||||||
const regex = /\/(\d+)/;
|
|
||||||
if (props.idInWhere) arrayData.store.filter.where = { id };
|
if (props.idInWhere) arrayData.store.filter.where = { id };
|
||||||
else if (!regex.test(props.url)) arrayData.store.url = `${props.url}/${id}`;
|
else {
|
||||||
jorgep marked this conversation as resolved
Outdated
|
|||||||
else arrayData.store.url = props.url.replace(regex, `/${id}`);
|
arrayData = getArrayData(id);
|
||||||
|
}
|
||||||
await arrayData.fetch({ append, updateRouter: false });
|
await arrayData.fetch({ append, updateRouter: false });
|
||||||
emit('onFetch', arrayData.store.data);
|
emit('onFetch', arrayData.store.data);
|
||||||
}
|
}
|
||||||
function hasRouteParam(params, valueToCheck = ':addressId') {
|
function hasRouteParam(params, valueToCheck = ':addressId') {
|
||||||
return Object.values(params).includes(valueToCheck);
|
return Object.values(params).includes(valueToCheck);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function formatUrl(id) {
|
||||||
|
const newId = id || entityId.value;
|
||||||
|
const regex = /\/(\d+)/;
|
||||||
|
if (!regex.test(props.url)) return `${props.url}/${newId}`;
|
||||||
|
return props.url.replace(regex, `/${newId}`);
|
||||||
|
}
|
||||||
|
|
||||||
|
function getArrayData(id, url) {
|
||||||
|
return useArrayData(props.dataKey, {
|
||||||
|
url: url ?? formatUrl(id),
|
||||||
|
userFilter: props.filter,
|
||||||
|
oneRecord: true,
|
||||||
|
});
|
||||||
|
}
|
||||||
</script>
|
</script>
|
||||||
<template>
|
<template>
|
||||||
<template v-if="visual">
|
<template v-if="visual">
|
||||||
|
|
Loading…
Reference in New Issue
Lo que estaba pasando, es que al hacer esto, no se cambiaba la url del arrayData (global) sino de la variable del modulo.
Entonces en un basicData, al guardar, cuando hace el reload, no ponia bien la url. Pq la url original era sin id.