- Through your
nuxt.config - Through the
useHeadcomposable - Through global meta components
title, titleTemplate, base, script, noscript, style, meta, link, htmlAttrs and bodyAttrs.
Migration Steps
- In your
nuxt.config, renameheadtometa- Consider moving this shared meta configuration into yourapp.vueinstead. Note that objects no longer have ahidkey for deduplication. - Migrate to
useHeadif you need to access component state - You might also consider using the built-in meta-components. - Use
head()method with Options API - If you need to use the Options API, there is ahead()method you can use when you usedefineNuxtComponent.
Using useHead
TheuseHead composable provides a reactive way to manage your head tags.
Key Differences
- No
hidproperty - Nuxt 3 uses thenameorpropertyattribute for deduplication - Reactive by default - Pass refs or computed values for reactivity
- Type-safe - Full TypeScript support
Using Meta Components
Nuxt 3 also provides meta components that you can use to accomplish the same task. While these components look similar to HTML tags, they are provided by Nuxt and have similar functionality.Important Notes
Available Meta Components
<Title>- Set the page title<Meta>- Set meta tags<Link>- Set link tags (favicons, stylesheets, etc.)<Style>- Set inline styles<Script>- Set script tags<NoScript>- Set noscript content<Base>- Set the base URL<Html>- Set HTML attributes<Body>- Set body attributes
Using Options API
If you must use the Options API, you can use thehead() method with defineNuxtComponent:
Nuxt 3 (Options API)
Common Meta Patterns
Dynamic Page Title
SEO Meta Tags
Adding External Scripts
Title Template
nuxt.config.ts
Migration Checklist
- Rename
headtometainnuxt.config - Remove
hidproperties from meta tags - Replace
head()option withuseHeadcomposable or meta components - Update any
this.$meta()calls to useuseHead - Make meta data reactive by using
reforcomputed