-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
64 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
}, | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters