This commit is contained in:
parent
a46d3affde
commit
9084d918c0
|
@ -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>
|
||||
|
|
|
@ -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>
|
||||
|
|
Loading…
Reference in New Issue