vue

Install Vue Unhead

Learn how to start using Unhead with Vue.

Setup

  1. Install @unhead/vue dependency to your project:
yarn
yarn add @unhead/vue
  1. Register the Vue plugin:
Vue 3
import { createApp } from 'vue'
import { createHead } from '@unhead/vue'
const app = createApp()
const head = createHead()
app.use(head)
app.mount('#app')
  1. Done! Now you can use the useHead composable to manage your head.
app.vue
<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: Options API Mixin

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>

Next Steps

Your Vue app is now setup for head management, congrats! 🎉

Try next:

  1. Optional: Setup SSR
  2. Add some recipes