@unhead/vue
@unhead/vue
Full-stack
<head>management for Vue applications
Features
- 🖖 Vue-optimized head management
- 🔄 Reactive titles, meta tags, and other head elements
- 🔍 SEO-friendly head control
- 🖥️ Server-side rendering support
- 📦 Lightweight with zero dependencies (except for Vue & unhead)
Installation
# npm
npm install @unhead/vue
# yarn
yarn add @unhead/vue
# pnpm
pnpm add @unhead/vue
[!TIP] Using an AI agent? Get the @unhead/vue Skill on skilld.dev/gh/unjs/unhead.
Usage
Setup
Client-side (SPA)
import { createHead } from '@unhead/vue/client'
// main.ts
import { createApp } from 'vue'
import App from './App.vue'
const app = createApp(App)
const head = createHead()
app.use(head)
app.mount('#app')
Server-side (SSR)
import { createHead } from '@unhead/vue/server'
// entry-server.ts
import { renderToString } from 'vue/server-renderer'
import { createApp } from './main'
export async function render(url: string) {
const { app } = createApp()
const head = createHead()
app.use(head)
const html = await renderToString(app)
return { html, head }
}
import { createHead } from '@unhead/vue/client'
// entry-client.ts (for hydration)
import { createApp } from './main'
const { app } = createApp()
const head = createHead()
app.use(head)
app.mount('#app')
Basic Usage
<!-- Home.vue -->
<script setup lang="ts">
import { useHead } from '@unhead/vue'
useHead({
title: 'Home Page',
meta: [
{
name: 'description',
content: 'Welcome to our website'
}
]
})
</script>
<template>
<h1>Home</h1>
</template>
Setting Meta Tags
<!-- About.vue -->
<script setup lang="ts">
import { useSeoMeta } from '@unhead/vue'
useSeoMeta({
title: 'About Us',
description: 'Learn more about our company',
ogTitle: 'About Our Company',
ogDescription: 'Our fantastic about page',
ogImage: 'https://example.com/image.jpg',
})
</script>
<template>
<h1>About Us</h1>
</template>
Reactive Head Elements
<!-- Profile.vue -->
<script setup lang="ts">
import { useHead } from '@unhead/vue'
import { ref } from 'vue'
const userName = ref('User')
// Vue automatically tracks reactive changes
useHead({
title: () => `${userName.value} - Profile`, // Reactive title
meta: [
{
name: 'description',
content: () => `${userName.value}'s profile page`, // Reactive description
},
],
})
function updateName() {
userName.value = 'New Name'
// Title and meta automatically update!
}
</script>
<template>
<h1>{{ userName }}'s Profile</h1>
<button @click="updateName">
Update Name
</button>
</template>
Development
# Install dependencies
npm install
# Generate build files
npm run build
# Run tests
npm run test
License
Related Packages
@unhead/schema-org-vue
Vue Schema.org for Simple and Automated Google Rich Results for everyone
62,919
383
Version History
| Version | Released | Vue | License |
|---|---|---|---|
| 3.4.3 | >=3.5.18 | MIT | |
| 3.4.2 | >=3.5.18 | MIT | |
| 3.4.1 | >=3.5.18 | MIT | |
| 3.4.0 | >=3.5.18 | MIT | |
| 3.3.2 | >=3.5.18 | MIT | |
| 3.3.1 | >=3.5.18 | MIT | |
| 3.3.0 | >=3.5.18 | MIT | |
| 3.2.3 | >=3.5.18 | MIT | |
| 3.2.2 | >=3.5.18 | MIT | |
| 3.2.1 | >=3.5.18 | MIT | |
| 3.2.0 | >=3.5.18 | MIT | |
| 3.1.8 | >=3.5.18 | MIT | |
| 3.1.7 | >=3.5.18 | MIT | |
| 3.1.6 | >=3.5.18 | MIT | |
| 3.1.5 | >=3.5.18 | MIT | |
| 3.1.4 | >=3.5.18 | MIT | |
| 3.1.3 | >=3.5.18 | MIT | |
| 3.1.2 | >=3.5.18 | MIT | |
| 3.1.1 | >=3.5.18 | MIT | |
| 3.1.0 | >=3.5.18 | MIT | |
| 3.0.5 | >=3.5.18 | MIT | |
| 3.0.4 | >=3.5.18 | MIT | |
| 3.0.3 | >=3.5.18 | MIT | |
| 3.0.2 | >=3.5.18 | MIT | |
| 3.0.1 | >=3.5.18 | MIT | |
| 3.0.0 | >=3.5.18 | MIT | |
| 2.1.17 | >=3.5.18 | MIT | |
| 2.1.16 | >=3.5.18 | MIT | |
| 2.1.15 | >=3.5.18 | MIT | |
| 2.1.13 | >=3.5.18 | MIT |
Showing the latest 30 of 245. See every release on npm
Pre-releases (85)
| Version | Released | Vue | License |
|---|---|---|---|
| 3.0.0-rc.4 | >=3.5.18 | MIT | |
| 3.0.0-rc.3 | >=3.5.18 | MIT | |
| 3.0.0-beta.12 | >=3.5.18 | MIT | |
| 3.0.0-beta.11 | >=3.5.18 | MIT | |
| 3.0.0-beta.10 | >=3.5.18 | MIT | |
| 3.0.0-beta.9 | >=3.5.18 | MIT | |
| 3.0.0-beta.8 | >=3.5.18 | MIT | |
| 3.0.0-beta.7 | >=3.5.18 | MIT | |
| 3.0.0-beta.6 | >=3.5.18 | MIT | |
| 3.0.0-beta.5 | >=3.5.18 | MIT | |
| 3.0.0-beta.4 | >=3.5.18 | MIT | |
| 3.0.0-beta.2 | >=3.5.18 | MIT | |
| 3.0.0-beta.1 | >=3.5.18 | MIT | |
| 2.0.0-rc.13 | >=3.5.13 | MIT | |
| 2.0.0-rc.12 | >=3.5.13 | MIT | |
| 2.0.0-rc.11 | >=3.5.13 | MIT | |
| 2.0.0-rc.10 | >=3.5.13 | MIT | |
| 2.0.0-rc.9 | >=3.5.13 | MIT | |
| 2.0.0-rc.8 | >=3.5.13 | MIT | |
| 2.0.0-rc.7 | >=3.5.13 | MIT | |
| 2.0.0-rc.6 | >=3.5.13 | MIT | |
| 2.0.0-rc.5 | >=3.5.13 | MIT | |
| 2.0.0-rc.3 | >=3.5.13 | MIT | |
| 2.0.0-rc.2 | >=3.5.13 | MIT | |
| 2.0.0-rc.1 | >=3.5.13 | MIT | |
| 2.0.0-beta.2 | >=3.5.13 | MIT | |
| 2.0.0-beta.1 | >=3.5.13 | MIT | |
| 2.0.0-beta.0 | >=3.5.13 | MIT | |
| 2.0.0-alpha.32 | >=3.5.13 | MIT | |
| 2.0.0-alpha.31 | >=3.5.13 | MIT |
Showing the latest 30 of 85. See every release on npm