Looking to enhance your website's SEO by adding title
, description
, and other HTML meta
tags?
Wondering how to achieve this in a Vue template?
For instance, let's say you want to include the meta
tags in your template.vue
file.
Additionally, you might need to add a script to that template for some reason.
Your current code resembles the following:
head: {
title: 'my title',
script: [
{ src: '/js/theme.js', defer: true }
]
},
The above code is throwing an error.
If you modify it like this:
head () {
return {
title: this.title,
meta: [
{ hid: 'description', name: 'description', content: 'My custom description' }
],
script: [
{ src: '/js/theme.js', defer: true }
]
}
}
The meta
tags will work as expected, but the script may not show up.
As mentioned earlier, you cannot place the script in the nuxt-config.js
file due to some unknown issue resulting in errors on the page.