mirror of
https://iceshrimp.dev/Crimekillz/jointrashposs.git
synced 2024-11-22 00:43:50 +01:00
(performance) fetch回数を減らす
This commit is contained in:
parent
c7d4147296
commit
d7805f7c4c
8
composables/useGAsyncData.ts
Normal file
8
composables/useGAsyncData.ts
Normal file
@ -0,0 +1,8 @@
|
||||
export function useGAsyncData(...params: Parameters<typeof useAsyncData>) {
|
||||
if (!params[2]) {
|
||||
params[2] = {};
|
||||
}
|
||||
params[2].getCachedData = (key) => useNuxtData(key).data.value ?? null;
|
||||
|
||||
return useAsyncData(...params);
|
||||
}
|
@ -12,12 +12,12 @@ const route = useRoute();
|
||||
const { locale } = useI18n();
|
||||
const navigation = ref();
|
||||
const asideNavKey = ref(0);
|
||||
const { data } = await useAsyncData(`navigation_${locale.value}`, () => fetchContentNavigation(queryContent(`/${locale.value}/docs/`)));
|
||||
const { data } = await useGAsyncData(`navigation_${locale.value}`, () => fetchContentNavigation(queryContent(`/${locale.value}/docs/`)));
|
||||
navigation.value = data.value;
|
||||
|
||||
watch(locale, async (to) => {
|
||||
console.log('locale changed');
|
||||
const { data } = await useAsyncData(`navigation_${to}`, () => fetchContentNavigation(queryContent(`/${to}/docs/`)));
|
||||
const { data } = await useGAsyncData(`navigation_${to}`, () => fetchContentNavigation(queryContent(`/${to}/docs/`)));
|
||||
navigation.value = data.value;
|
||||
asideNavKey.value++;
|
||||
});
|
||||
|
@ -66,7 +66,7 @@ onBeforeRouteLeave((to) => {
|
||||
// ▲他言語からやってきたときに正しいパスに戻す▲
|
||||
|
||||
const runtimeConfig = useRuntimeConfig();
|
||||
const { data } = await useAsyncData(`blog-${route.params.slug}`, () => queryContent<MiBlogParsedContent>(`/blog/${route.params.slug}`).findOne());
|
||||
const { data } = await useGAsyncData(`blog-${route.params.slug}`, () => queryContent<MiBlogParsedContent>(`/blog/${route.params.slug}`).findOne());
|
||||
|
||||
if (!data.value) {
|
||||
throw createError({ statusCode: 404, statusMessage: 'page not found', fatal: true });
|
||||
|
@ -38,7 +38,7 @@ const route = useRoute();
|
||||
const localeState = useState('miHub_blog_originalLocale', () => locale.value);
|
||||
localeState.value = locale.value;
|
||||
|
||||
const { data } = await useAsyncData('blog', () => queryContent('blog').only(['_path', 'navTitle', 'title', 'date']).sort({ date: -1 }).find());
|
||||
const { data } = await useGAsyncData('blog', () => queryContent('blog').only(['_path', 'navTitle', 'title', 'date']).sort({ date: -1 }).find());
|
||||
const localePath = useGLocalePath();
|
||||
|
||||
route.meta.title = t('_blog.title');
|
||||
|
@ -64,7 +64,7 @@ definePageMeta({
|
||||
const route = useRoute();
|
||||
const slugs = (route.params.slug as string[]).filter((v) => v !== '');
|
||||
|
||||
const { data } = await useAsyncData(`docs-${locale.value}-${slugs.join('-')}`, () => queryContent<MiDocsParsedContent>(`/${locale.value}/docs/${slugs.join('/')}`).findOne());
|
||||
const { data } = await useGAsyncData(`docs-${locale.value}-${slugs.join('-')}`, () => queryContent<MiDocsParsedContent>(`/${locale.value}/docs/${slugs.join('/')}`).findOne());
|
||||
|
||||
if (!data.value) {
|
||||
throw createError({ statusCode: 404, statusMessage: 'page not found', fatal: true });
|
||||
|
@ -36,7 +36,7 @@ defineI18nRoute(false);
|
||||
|
||||
const route = useRoute();
|
||||
|
||||
const { data } = await useAsyncData('global-ns', () => queryContent(`/ns`).findOne());
|
||||
const { data } = await useGAsyncData('global-ns', () => queryContent(`/ns`).findOne());
|
||||
|
||||
if (!data.value) {
|
||||
throw createError({ statusCode: 404, statusMessage: 'page not found', fatal: true });
|
||||
|
Loading…
Reference in New Issue
Block a user