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

View File

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

View File

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

View File

@ -8,15 +8,12 @@
import type { BlogPost } from '~~/lib/types/post';
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: {
year: route.params.year,
body: false,
render: false,
},
});
onMounted(() => {
refresh();
});
</script>

View File

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

View File

@ -8,15 +8,12 @@
import type { BlogPost } from '~~/lib/types/post';
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: {
tag: route.params.tag,
body: false,
render: false,
},
});
onMounted(() => {
refresh();
});
</script>