add keys to fetches

This commit is contained in:
Evert Prants 2022-10-16 14:34:04 +03:00
parent 44543b5992
commit b6b84cfa33
Signed by: evert
GPG Key ID: 1688DA83D222D0B5
6 changed files with 14 additions and 26 deletions

View File

@ -26,8 +26,11 @@
import type { BlogPost } from '~~/lib/types/post'; import type { BlogPost } from '~~/lib/types/post';
const route = useRoute(); const route = useRoute();
const { data: post, refresh } = await useFetch<BlogPost>( const { data: post } = await useFetch<BlogPost>(
`/api/blog/${route.params.slug}` `/api/blog/${route.params.slug}`,
{
key: `${route.params.slug}-post`,
}
); );
const isostamp = computed(() => new Date(post.value.date).toISOString()); const isostamp = computed(() => new Date(post.value.date).toISOString());
@ -37,8 +40,4 @@ const preview = computed(() =>
.replace('\n', ' ') .replace('\n', ' ')
.substring(0, 120) .substring(0, 120)
); );
onMounted(() => {
refresh();
});
</script> </script>

View File

@ -8,7 +8,8 @@
import type { BlogPost } from '~~/lib/types/post'; import type { BlogPost } from '~~/lib/types/post';
const route = useRoute(); const route = useRoute();
const { data: posts, refresh } = await useFetch<BlogPost[]>(`/api/blog`, { const { data: posts } = await useFetch<BlogPost[]>(`/api/blog`, {
key: `${route.params.year}-${route.params.month}-${route.params.day}-page`,
params: { params: {
year: route.params.year, year: route.params.year,
month: route.params.month, month: route.params.month,
@ -17,8 +18,4 @@ const { data: posts, refresh } = await useFetch<BlogPost[]>(`/api/blog`, {
render: false, render: false,
}, },
}); });
onMounted(() => {
refresh();
});
</script> </script>

View File

@ -8,7 +8,8 @@
import type { BlogPost } from '~~/lib/types/post'; import type { BlogPost } from '~~/lib/types/post';
const route = useRoute(); const route = useRoute();
const { data: posts, refresh } = await useFetch<BlogPost[]>(`/api/blog`, { const { data: posts } = await useFetch<BlogPost[]>(`/api/blog`, {
key: `${route.params.year}-${route.params.month}-page`,
params: { params: {
year: route.params.year, year: route.params.year,
month: route.params.month, month: route.params.month,
@ -16,8 +17,4 @@ const { data: posts, refresh } = await useFetch<BlogPost[]>(`/api/blog`, {
render: false, render: false,
}, },
}); });
onMounted(() => {
refresh();
});
</script> </script>

View File

@ -8,15 +8,12 @@
import type { BlogPost } from '~~/lib/types/post'; import type { BlogPost } from '~~/lib/types/post';
const route = useRoute(); const route = useRoute();
const { data: posts, refresh } = await useFetch<BlogPost[]>(`/api/blog`, { const { data: posts } = await useFetch<BlogPost[]>(`/api/blog`, {
key: `${route.params.year}-archive-page`,
params: { params: {
year: route.params.year, year: route.params.year,
body: false, body: false,
render: false, render: false,
}, },
}); });
onMounted(() => {
refresh();
});
</script> </script>

View File

@ -8,6 +8,7 @@
import type { BlogPost } from '~~/lib/types/post'; import type { BlogPost } from '~~/lib/types/post';
const { data: posts } = await useFetch<BlogPost[]>(`/api/blog`, { const { data: posts } = await useFetch<BlogPost[]>(`/api/blog`, {
key: `blog-archive`,
params: { params: {
body: false, body: false,
render: false, render: false,

View File

@ -8,15 +8,12 @@
import type { BlogPost } from '~~/lib/types/post'; import type { BlogPost } from '~~/lib/types/post';
const route = useRoute(); const route = useRoute();
const { data: posts, refresh } = await useFetch<BlogPost[]>(`/api/blog`, { const { data: posts } = await useFetch<BlogPost[]>(`/api/blog`, {
key: `${route.params.tag}-tag-page`,
params: { params: {
tag: route.params.tag, tag: route.params.tag,
body: false, body: false,
render: false, render: false,
}, },
}); });
onMounted(() => {
refresh();
});
</script> </script>