Skip to content

Commit

Permalink
chore: update example code
Browse files Browse the repository at this point in the history
  • Loading branch information
ymmooot committed Dec 11, 2024
1 parent 47f159d commit 7144b70
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 3 deletions.
34 changes: 34 additions & 0 deletions packages/example/composables/dog.ts
Original file line number Diff line number Diff line change
@@ -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,
},
};
};
2 changes: 1 addition & 1 deletion packages/example/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
26 changes: 26 additions & 0 deletions packages/example/pages/context.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<template>
<div>
<h1>Context example</h1>
<div>
<pre>{{ JSON.stringify(data.dog, null, 4) }}</pre>
<nuxt-link to="/"> Back to list </nuxt-link>
</div>
</div>
</template>

<script lang="ts" setup>
import { useDog } from '@/composables/dog';
const { data } = await useDog();
</script>

<style scoped>
pre {
display: block;
margin: 10px auto;
max-width: 300px;
padding: 12px;
text-align: left;
background-color: gainsboro;
border-radius: 4px;
}
</style>
3 changes: 2 additions & 1 deletion packages/example/pages/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,13 @@
<li><nuxt-link :to="{ name: 'static' }">Static JSON</nuxt-link></li>
<li><nuxt-link :to="{ name: 'option' }">Options API</nuxt-link></li>
<li><nuxt-link :to="{ name: 'composable-options' }">Composable API Options</nuxt-link></li>
<li><nuxt-link :to="{ name: 'context' }">Context</nuxt-link></li>
</ul>
</div>
</template>

<script lang="ts">
import { WithContext, ItemList } from 'schema-dts';
import type { WithContext, ItemList } from 'schema-dts';
export default defineComponent({
setup() {
Expand Down
2 changes: 1 addition & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -7553,7 +7553,7 @@ nuxi@^3.15.0:
resolved "https://registry.yarnpkg.com/nuxi/-/nuxi-3.15.0.tgz#ed54923ca46727c6e7df10495143db340d9791c9"
integrity sha512-ZVu45nuDrdb7nzKW2kLGY/N1vvFYLLbUVX6gUYw4BApKGGu4+GktTR5o48dGVgMYX9A8chaugl7TL9ZYmwC9Mg==

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

0 comments on commit 7144b70

Please sign in to comment.