From 03644af67848b51173997698465d4af93d1ebe60 Mon Sep 17 00:00:00 2001 From: DanSnow Date: Wed, 7 Jun 2023 20:02:35 +0800 Subject: [PATCH] fix(karbon): page meta could be undefined when changing page --- packages/karbon/src/runtime/composables/page-meta.ts | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/packages/karbon/src/runtime/composables/page-meta.ts b/packages/karbon/src/runtime/composables/page-meta.ts index 5fcff571..582f9d98 100644 --- a/packages/karbon/src/runtime/composables/page-meta.ts +++ b/packages/karbon/src/runtime/composables/page-meta.ts @@ -1,5 +1,5 @@ import type { Ref } from 'vue' -import { useCurrentElement } from '@vueuse/core' +import { useCurrentElement, whenever } from '@vueuse/core' import type { EventName } from '../api/track' import type { UseArticleReturn as Article } from '../types' import { useSEO } from './seo' @@ -75,11 +75,17 @@ export function setupPage({ type, seo = true }: SetupPage if (type === 'article') { const { $paywall } = useNuxtApp() - const { id, plan } = meta.value onMounted(() => { $paywall.mount() $paywall.enable() - $paywall.setArticle({ id, plan }) + + whenever( + meta, + ({ id, plan }) => { + $paywall.setArticle({ id, plan }) + }, + { immediate: true, flush: 'sync' } + ) }) onBeforeUnmount(() => { $paywall.disable()