From 73c35b3c11343e173e2670e12bb3326ec9376e3b Mon Sep 17 00:00:00 2001 From: Anthony Fu Date: Thu, 24 Nov 2022 12:02:18 +0800 Subject: [PATCH] perf: improve navigation speed --- components/status/StatusCard.vue | 12 ++++++--- package.json | 1 + pages/@[user]/[post].vue | 22 ++++++++++------ pnpm-lock.yaml | 44 +++++++++++++++++++++++++++----- 4 files changed, 61 insertions(+), 18 deletions(-) diff --git a/components/status/StatusCard.vue b/components/status/StatusCard.vue index 6debcf14..c28ef865 100644 --- a/components/status/StatusCard.vue +++ b/components/status/StatusCard.vue @@ -22,11 +22,17 @@ const rebloggedBy = $computed(() => props.status.reblog ? props.status.account : const el = ref() const router = useRouter() -function go(e: MouseEvent) { +function onclick(e: MouseEvent) { const path = e.composedPath() as HTMLElement[] const el = path.find(el => ['A', 'BUTTON', 'IMG', 'VIDEO'].includes(el.tagName?.toUpperCase())) if (!el) - router.push(getStatusPath(status)) + go() +} + +function go() { + // cache data + useNuxtApp().payload.data[`status-${status.id}`] = status + router.push(getStatusPath(status)) } const timeago = useTimeAgo(() => status.createdAt, { @@ -63,7 +69,7 @@ const timeago = useTimeAgo(() => status.createdAt, {