From 9084d918c04c284f2f80dd13b31dc2becf35ec4d Mon Sep 17 00:00:00 2001 From: jorgep Date: Thu, 9 Jan 2025 17:32:57 +0100 Subject: [PATCH] fix: refs #6919 arrayData --- src/components/common/VnCard.vue | 10 ++++++---- src/components/common/VnCardBeta.vue | 10 ++++++---- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/src/components/common/VnCard.vue b/src/components/common/VnCard.vue index 064f85337..cf98a0ab2 100644 --- a/src/components/common/VnCard.vue +++ b/src/components/common/VnCard.vue @@ -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 }); } diff --git a/src/components/common/VnCardBeta.vue b/src/components/common/VnCardBeta.vue index 0afd1c211..23a45974f 100644 --- a/src/components/common/VnCardBeta.vue +++ b/src/components/common/VnCardBeta.vue @@ -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 }); }