useSchemaOrg() for type-safe markup with automatic graph linkingSchema.org structured data helps Google display Rich Results—stars, FAQs, recipes, product prices. Rotten Tomatoes saw a 25% higher click-through rate on pages with structured data compared to pages without.
<!-- JSON-LD structured data in the head -->
<script type="application/ld+json">
{
"@context": "https://schema.org",
"@type": "Article",
"headline": "Add JSON-LD Structured Data in Vue",
"author": { "@type": "Person", "name": "Your Name" }
}
</script>
Google recommends JSON-LD as the easiest format to implement and maintain. Common rich result types:
Rich results aren't guaranteed. Content must match the markup and follow Google's structured data guidelines.
Vue uses Unhead for head management. You can add JSON-LD via useHead(), but useSchemaOrg() from @unhead/schema-org provides type safety and automatic graph linking.
pnpm add -D @unhead/schema-org
See Unhead Schema.org setup for full install instructions.
import { defineArticle, useSchemaOrg } from '@unhead/schema-org/vue'
useSchemaOrg([
defineArticle({
headline: 'Add JSON-LD Structured Data in Vue',
author: { name: 'Your Name' },
datePublished: new Date(2024, 0, 15),
})
])
useHead({
script: [
{
type: 'application/ld+json',
innerHTML: JSON.stringify({
'@context': 'https://schema.org',
'@type': 'Article',
'headline': 'Add JSON-LD Structured Data in Vue',
'author': { '@type': 'Person', 'name': 'Your Name' }
})
}
],
})
The defineX() helpers align with Google's Structured Data Guidelines and handle boilerplate:
| Helper | Rich Result Type |
|---|---|
defineArticle() | Article, NewsArticle, BlogPosting |
defineBreadcrumb() | Breadcrumb navigation |
defineQuestion() | FAQ pages |
defineProduct() | Product listings |
useSchemaOrg() accepts refs and computed getters:
const article = ref({
title: 'My Article',
description: 'Article description'
})
useSchemaOrg([
defineArticle({
headline: () => article.value.title,
description: () => article.value.description,
})
])
Set up base schema in your root component. Child components can add specific types that link to this graph automatically.
<script lang="ts" setup>
import { defineOrganization, defineWebPage, defineWebSite, useSchemaOrg } from '@unhead/schema-org/vue'
const route = useRoute()
useHead({
templateParams: {
schemaOrg: {
host: 'https://mysite.com',
path: route.path,
inLanguage: 'en',
}
}
})
useSchemaOrg([
defineWebPage(),
defineWebSite({
name: 'My Site',
description: 'What my site does.',
}),
// Use defineOrganization for businesses, definePerson for personal sites
defineOrganization({
name: 'My Company',
logo: '/logo.png',
})
])
</script>
Vue's hierarchical head system means you don't need to repeat WebSite and WebPage if they're in the layout:
<script lang="ts" setup>
import { defineArticle, useSchemaOrg } from '@unhead/schema-org/vue'
const article = await fetchArticle()
useSchemaOrg([
defineArticle({
headline: article.title,
image: article.image,
datePublished: article.publishedAt,
dateModified: article.updatedAt,
author: {
name: article.author.name,
url: article.author.url,
}
})
])
</script>
Use Google's Rich Results Test to validate your structured data. Enter your URL or paste the HTML directly. The tool shows which rich results are eligible and flags any errors.
For local development, inspect the <head> to verify the JSON-LD script tag is present and valid JSON.
Nuxt SEO handles Schema.org automatically with zero config. See the Nuxt Schema.org guide for the Nuxt-specific approach.
Which format does Google recommend for structured data?
Microdata - Older format, harder to maintain and debugJSON-LD - Correct! Google recommends JSON-LD as easiest to implement and maintainRDFa - Supported but not recommended by Google