In this article, we will learn how to add the meta tags using unhead in vue.js
Step 1: Create a new Vue project:
vue create unhead-demo
Step 2: Install require packages:
nmpm i vue-router unhead
Step3: Open main.js file and add the following in it:
import { createApp } from 'vue' import App from './App.vue' import { createHead } from 'unhead' const head = createHead() createApp(App).use(head).mount('#app')
Step 4: Open App.vue file and add the following in it:
<template> <img alt="Vue logo" src="./assets/logo.png" /> <h1>Unhead demo</h1> </template> <script> import { useHead } from "unhead"; export default { name: "App", mounted() { useHead({ title: "My demo site", meta: [ { name: "title", content: "My demo site", }, ], link: [ { rel: "stylesheet", href: "https://cdn.jsdelivr.net/npm/bootstrap@4.4.1/dist/css/bootstrap.min.css", }, ], }); }, }; </script> <style> #app { font-family: Avenir, Helvetica, Arial, sans-serif; -webkit-font-smoothing: antialiased; -moz-osx-font-smoothing: grayscale; text-align: center; color: #2c3e50; margin-top: 60px; } </style>
Code in Action: