Skip to content

Commit 7144b70

Browse files
committed
chore: update example code
1 parent 47f159d commit 7144b70

File tree

5 files changed

+64
-3
lines changed

5 files changed

+64
-3
lines changed

packages/example/composables/dog.ts

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import type { NuxtApp } from '#app';
2+
3+
type Dog = {
4+
breed: string;
5+
name: string;
6+
age: number;
7+
};
8+
9+
export const useDog = async () => {
10+
const app = useNuxtApp();
11+
12+
// fetch Dog data
13+
await new Promise((res) => setTimeout(res, 100));
14+
const dog: Dog = {
15+
breed: 'Golden Retriever',
16+
name: 'Buddy',
17+
age: 5,
18+
};
19+
20+
app.runWithContext(() => {
21+
useJsonld(() => ({
22+
'@context': 'https://schema.org',
23+
'@type': 'Thing',
24+
name: dog.name,
25+
description: `A ${dog.breed} dog`,
26+
}));
27+
});
28+
29+
return {
30+
data: {
31+
dog,
32+
},
33+
};
34+
};

packages/example/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
"start": "node ./.output/server/index.mjs"
1010
},
1111
"dependencies": {
12-
"nuxt": "^3.11.2"
12+
"nuxt": "^3.12.4"
1313
},
1414
"devDependencies": {
1515
"@nuxt/devtools": "^0.8.5"

packages/example/pages/context.vue

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<template>
2+
<div>
3+
<h1>Context example</h1>
4+
<div>
5+
<pre>{{ JSON.stringify(data.dog, null, 4) }}</pre>
6+
<nuxt-link to="/"> Back to list </nuxt-link>
7+
</div>
8+
</div>
9+
</template>
10+
11+
<script lang="ts" setup>
12+
import { useDog } from '@/composables/dog';
13+
const { data } = await useDog();
14+
</script>
15+
16+
<style scoped>
17+
pre {
18+
display: block;
19+
margin: 10px auto;
20+
max-width: 300px;
21+
padding: 12px;
22+
text-align: left;
23+
background-color: gainsboro;
24+
border-radius: 4px;
25+
}
26+
</style>

packages/example/pages/index.vue

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,13 @@
1111
<li><nuxt-link :to="{ name: 'static' }">Static JSON</nuxt-link></li>
1212
<li><nuxt-link :to="{ name: 'option' }">Options API</nuxt-link></li>
1313
<li><nuxt-link :to="{ name: 'composable-options' }">Composable API Options</nuxt-link></li>
14+
<li><nuxt-link :to="{ name: 'context' }">Context</nuxt-link></li>
1415
</ul>
1516
</div>
1617
</template>
1718

1819
<script lang="ts">
19-
import { WithContext, ItemList } from 'schema-dts';
20+
import type { WithContext, ItemList } from 'schema-dts';
2021
2122
export default defineComponent({
2223
setup() {

yarn.lock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7553,7 +7553,7 @@ nuxi@^3.15.0:
75537553
resolved "https://registry.yarnpkg.com/nuxi/-/nuxi-3.15.0.tgz#ed54923ca46727c6e7df10495143db340d9791c9"
75547554
integrity sha512-ZVu45nuDrdb7nzKW2kLGY/N1vvFYLLbUVX6gUYw4BApKGGu4+GktTR5o48dGVgMYX9A8chaugl7TL9ZYmwC9Mg==
75557555

7556-
nuxt@^3.11.2:
7556+
nuxt@^3.11.2, nuxt@^3.12.4:
75577557
version "3.14.1592"
75587558
resolved "https://registry.yarnpkg.com/nuxt/-/nuxt-3.14.1592.tgz#0f94132b7e0ffe9087b37392f295e2c7d5d05ee3"
75597559
integrity sha512-roWAQH4Mb6WY72cNos+YVw0DgTCNAhNygiAMCedM7hbX6ESTR2n3VH7tU0yIWDPe/hfFdii4M4wWTTNHOtS44g==

0 commit comments

Comments
 (0)