Vue
Install Vue Unhead
Learn how to start using Unhead with Vue.
Setup
- Install
@unhead/vue
dependency to your project:
yarn
yarn add @unhead/vue
Demos
- Register the Vue plugin:
Vue 3
import { createHead } from '@unhead/vue'
import { createApp } from 'vue'
const app = createApp()
const head = createHead()
app.use(head)
app.mount('#app')
- Done! Now you can use the
useHead
composable to manage your head.
useHead
<script setup lang=ts>
import { useHead } from '@unhead/vue'
useHead({
title: 'My awesome site'
})
</script>
Optional: Auto-Imports
Unhead provides out-of-the-box configuration for unplugin-auto-import.
vite.config.ts
import { unheadVueComposablesImports } from '@unhead/vue'
export default defineConfig({
plugins: [
AutoImport({
imports: [
unheadVueComposablesImports,
],
}),
]
})
Optional: Vue 3 Options API
The options API functionality is only provided out-of-the-box for Vue 2, if you'd like to use in Vue 3 you will need to install the mixin.
import { createHead, VueHeadMixin } from '@unhead/vue'
import { createApp } from 'vue'
const app = createApp()
const head = createHead()
app.mixin(VueHeadMixin)
// ...
This key can either be a function or a plain object or reactive data. See Reactivity for more details.
<script>
export default {
head() {
return {
title: 'Hello World'
}
}
}
</script>
<template>
<div>
<h1>Hello World</h1>
</div>
</template>
Next Steps
Your Vue app is now setup for head management, congrats! 🎉
Try next:
- Optional: Setup SSR
- Explore the Composables