diff --git a/packages/example/composables/dog.ts b/packages/example/composables/dog.ts new file mode 100644 index 00000000..0cd78cd7 --- /dev/null +++ b/packages/example/composables/dog.ts @@ -0,0 +1,34 @@ +import type { NuxtApp } from '#app'; + +type Dog = { + breed: string; + name: string; + age: number; +}; + +export const useDog = async () => { + const app = useNuxtApp(); + + // fetch Dog data + await new Promise((res) => setTimeout(res, 100)); + const dog: Dog = { + breed: 'Golden Retriever', + name: 'Buddy', + age: 5, + }; + + app.runWithContext(() => { + useJsonld(() => ({ + '@context': 'https://schema.org', + '@type': 'Thing', + name: dog.name, + description: `A ${dog.breed} dog`, + })); + }); + + return { + data: { + dog, + }, + }; +}; diff --git a/packages/example/package.json b/packages/example/package.json index 22f6c3d8..84c2b7cf 100644 --- a/packages/example/package.json +++ b/packages/example/package.json @@ -9,7 +9,7 @@ "start": "node ./.output/server/index.mjs" }, "dependencies": { - "nuxt": "^3.11.2" + "nuxt": "^3.12.4" }, "devDependencies": { "@nuxt/devtools": "^0.8.5" diff --git a/packages/example/pages/context.vue b/packages/example/pages/context.vue new file mode 100644 index 00000000..951b92d6 --- /dev/null +++ b/packages/example/pages/context.vue @@ -0,0 +1,26 @@ + + + + + diff --git a/packages/example/pages/index.vue b/packages/example/pages/index.vue index f7649465..187e904f 100644 --- a/packages/example/pages/index.vue +++ b/packages/example/pages/index.vue @@ -11,12 +11,13 @@
  • Static JSON
  • Options API
  • Composable API Options
  • +
  • Context