Vue Tip: Use a Head Manager
Unhead is a framework-agnostic document head manager that you can use to manage page metadata like the title in your Vue application. It's used in the Nuxt core and is part of the UnJS ecosystem.
Installation
First, you need to install the @unhead/vue
dependency to your project:
Next, you need to register the Vue plugin:
Usage
Now, you can use the useHead
composable in your components, for example, to set the page title:
Alternatively, you can use the <Head>
component to set the page title:
And that's it. You can find more information in the official documentation.
If you liked this Vue tip, follow me on X to get notified about new tips, blog posts, and more. Alternatively (or additionally), you can subscribe to my weekly Vue & Nuxt newsletter:
Vue Tip: Automatically Import Components
Use the unplugin-vue-components tool to automatically import your Vue components.
Vue Tip: Composable to Define Keyboard Shortcuts
I show you a handy Vue composable that allows you to define keyboard shortcuts in your app.