#6919 syncData #941

Merged
jorgep merged 95 commits from 6919-syncData into dev 2025-02-06 09:39:49 +00:00
2 changed files with 12 additions and 8 deletions
Showing only changes of commit 9084d918c0 - Show all commits

View File

@ -36,7 +36,7 @@ const arrayData = useArrayData(props.dataKey, {
onBeforeMount(async () => {
try {
await fetchData(route.params.id);
await fetch(route.params.id);
} catch {
const { matched: matches } = router.currentRoute.value;
const { path } = matches.at(-1);
@ -46,12 +46,14 @@ onBeforeMount(async () => {
onBeforeRouteUpdate(async (to, from) => {
const id = to.params.id;
if (id !== from.params.id) await fetchData(id, true);
if (id !== from.params.id) await fetch(id, true);
});
async function fetchData(id, append = false) {
async function fetch(id, append = false) {
const regex = /\/(\d+)/;
if (props.idInWhere) arrayData.store.filter.where = { id };
else arrayData.store.url = props.url.replace(/(\/\d+)/, `/${id}`);
else if (!regex.test(props.url)) arrayData.store.url = `${props.url}/${id}`;
else arrayData.store.url = props.url.replace(regex, `/${id}`);
await arrayData.fetch({ append, updateRouter: false });
}
</script>

View File

@ -30,7 +30,7 @@ const arrayData = useArrayData(props.dataKey, {
onBeforeMount(async () => {
const route = router.currentRoute.value;
try {
await fetchData(route.params.id);
await fetch(route.params.id);
} catch {
const { matched: matches } = route;
const { path } = matches.at(-1);
@ -40,12 +40,14 @@ onBeforeMount(async () => {
onBeforeRouteUpdate(async (to, from) => {
const id = to.params.id;
if (id !== from.params.id) await fetchData(id, true);
if (id !== from.params.id) await fetch(id, true);
});
async function fetchData(id, append = false) {
async function fetch(id, append = false) {
const regex = /\/(\d+)/;
if (props.idInWhere) arrayData.store.filter.where = { id };
else arrayData.store.url = props.url.replace(/(\/\d+)/, `/${id}`);
else if (!regex.test(props.url)) arrayData.store.url = `${props.url}/${id}`;
else arrayData.store.url = props.url.replace(regex, `/${id}`);
await arrayData.fetch({ append, updateRouter: false });
}
</script>