vue
Learn how to start using Unhead with Vue.
@unhead/vue
dependency to your project:yarn add @unhead/vue
import { createApp } from 'vue'
import { createHead } from '@unhead/vue'
const app = createApp()
const head = createHead()
app.use(head)
app.mount('#app')
useHead
composable to manage your head.<script setup lang=ts>
import { useHead } from '@unhead/vue'
useHead({
title: 'My awesome site'
})
</script>
Unhead provides out-of-the-box configuration for unplugin-auto-import.
import { unheadVueComposablesImports } from '@unhead/vue'
export default defineConfig({
plugins: [
AutoImport({
imports: [
unheadVueComposablesImports,
],
}),
]
})
If you prefer using the options API, you will need to use the VueHeadMixin
mixin.
import { createApp } from 'vue'
import { VueHeadMixin, createHead } from '@unhead/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>
Your Vue app is now setup for head management, congrats! 🎉
Try next: