Installation
Requirements
- Nuxt
3.0.0or newer - A package manager supported by your Nuxt project
Install the package
bash
pnpm add @avensio/nuxt-jsonldbash
npm install @avensio/nuxt-jsonldbash
yarn add @avensio/nuxt-jsonldbash
nuxi module add @avensio/nuxt-jsonldRegister the module
When installing with pnpm, npm or yarn; add the module to nuxt.config.ts:
ts
export default defineNuxtConfig({
modules: ['@avensio/nuxt-jsonld'],
})The module auto-imports useJsonLd, useJsonLdPreset, and useObjectPresetStore.
Add your first object
Call useJsonLd from a page, layout, component, or plugin:
vue
<script setup lang="ts">
useJsonLd({
'@type': 'Organization',
'@id': 'https://example.com/#organization',
name: 'Example Inc.',
url: 'https://example.com/',
})
</script>You may omit @context. The module adds https://schema.org to the generated graph.
Check the result
Start Nuxt and inspect the page head. It contains one script with the key jsonld-graph:
vue
<script type="application/ld+json">
{
"@context": "https://schema.org",
"@graph": [
{
"@type": "Organization",
"@id": "https://example.com/#organization",
"name": "Example Inc.",
"url": "https://example.com/",
}
]
}
</script>The graph array contains the objects registered globally for the application and current route.