vue 单页面 keywords description title

router.beforeEach((to, from, next) => {
/* 路由发生变化修改页面title */
if (to.meta.title) {
document.title = to.meta.title
}
if(to.meta.content){

// public/index.html 写好标签
document.querySelector('meta[name="Keywords"]').setAttribute('content', "keywords")
document.querySelector('meta[name="Description"]').setAttribute('content', "description")
document.title = "title";

/*


let head = document.getElementsByTagName('head');
let meta = document.createElement('meta');
document.querySelector('meta[name="keywords"]').setAttribute('content', to.meta.content.keywords)
document.querySelector('meta[name="description"]').setAttribute('content', to.meta.content.description)
meta.content = to.meta.content;
head[0].appendChild(meta)

*/

 


}
next()
})

posted @ 2021-03-02 17:12  mrt_yy  阅读(294)  评论(0编辑  收藏  举报