tapitapi’s blog

1日1杯タピオカ!エンジニア

【Nuxt.js】metaタグにhttp-equivを設定する

Nuxtを使ってmetaタグにhttp-equivを設定する時、ハマったので備忘録

 

nuxt.config.jsに

head: {
title: process.env.npm_package_name || '',
meta: [
{ charset: 'utf-8' },
{ http-equiv: 'X-UA-Compatible', content: 'IE=edge' },
{ name: 'viewport', content: 'width=device-width, initial-scale=1.0' },
{ hid: 'description', name: 'description', content: 'default-description' }
]

}

 のように設定した時、”SyntaxError: Unexpected token -” エラーが出て、http-equivが設定できませんでした

 

下記のようにhttp-equivを’’で囲むことで解決。

head: {
title: process.env.npm_package_name || '',
meta: [
{ charset: 'utf-8' },
{ ’http-equiv': 'X-UA-Compatible', content: 'IE=edge' },
{ name: 'viewport', content: 'width=device-width, initial-scale=1.0' },
{ hid: 'description', name: 'description', content: 'default-description' }
]

}

 

下記参考にした記事

1. 同じ症状のIssue

github.com

 

 

2. http-equivについて(http-equivは、日本語の文字化けなどを防ぐために設定します。)

www5.plala.or.jp


 

3.Nustでmetaタグを設定する方法

qiita.com

 

以上ですーーー!!

 

おやすみなさいぃぃ