-
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
10 changed files
with
125 additions
and
132 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
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,32 @@ | ||
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, | ||
}; | ||
|
||
// Note: This jsonld will not disappear even after page transition. | ||
// If you want to link it to the page, use useJsonld in the component side. | ||
app.runWithContext(() => { | ||
useJsonld(() => ({ | ||
'@context': 'https://schema.org', | ||
'@type': 'Thing', | ||
name: dog.name, | ||
description: `A ${dog.breed} dog: not linked to the page`, | ||
})); | ||
}); | ||
|
||
return { | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,5 @@ | ||
import NuxtJsonld from 'nuxt-jsonld'; | ||
|
||
export default defineNuxtConfig({ | ||
modules: [NuxtJsonld], | ||
modules: ['nuxt-jsonld'], | ||
css: ['@/css/index.css'], | ||
devtools: true, | ||
compatibilityDate: '2024-12-11', | ||
}); |
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 |
---|---|---|
@@ -1,24 +1,21 @@ | ||
<template> | ||
<div> | ||
<h1>Composable Options</h1> | ||
<nuxt-link to="/"> Back to list </nuxt-link> | ||
</div> | ||
</template> | ||
|
||
<script lang="ts"> | ||
export default defineComponent({ | ||
setup() { | ||
useJsonld( | ||
() => { | ||
return { | ||
'@context': 'https://schema.org', | ||
'@type': 'WebSite', | ||
name: 'nuxt-jsonld composable options', | ||
}; | ||
}, | ||
{ | ||
tagPosition: 'bodyClose', | ||
} | ||
); | ||
<script lang="ts" setup> | ||
useJsonld( | ||
() => { | ||
return { | ||
'@context': 'https://schema.org', | ||
'@type': 'WebSite', | ||
name: 'nuxt-jsonld composable options', | ||
}; | ||
}, | ||
}); | ||
{ | ||
tagPosition: 'bodyClose', | ||
} | ||
); | ||
</script> |
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,32 @@ | ||
<template> | ||
<div> | ||
<h1>Context example</h1> | ||
<div> | ||
<pre>{{ JSON.stringify(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 { dog } = await useDog(); | ||
useJsonld(() => ({ | ||
'@context': 'https://schema.org', | ||
'@type': 'Thing', | ||
name: dog.name, | ||
description: `A ${dog.breed} dog: linked to this page`, | ||
})); | ||
</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
This file was deleted.
Oops, something went wrong.
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