Vueのコード
-
JAVASCRIPT Vue JSでtitleやmetaタグを動的に変更する<script> export default { name: 'home', mounted: function(){ const title = "タイトル" const description = "説明文" document.title = title document.querySelector("meta[property='og:title']").setAttribute('content', title) document.querySelector("meta[name='description']").setAttribute('content', description) document.querySelector("meta[property='og:description']").setAttribute('content', description) } } </script>
-
JAVASCRIPT Vueのindex.html<!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <meta name="viewport" content="width=device-width,initial-scale=1.0"> <meta name="format-detection" content="telephone=no"> <title>vue-skeleton</title> <meta name="robots" content="noindex,nofollow"> <link rel="stylesheet" href="/css/style.css"> </head> <body> <div id="app"></div> <script src="/js/bundle.js"></script> </body> </html>