1、在vue中路由的meta添加自定义对象
2、在main.js中全局配置
router.beforeEach((to, from, next)=>{
if(to.meta.content) { //路由发生变化时候修改meta中的content
let head = document.getElementByTagName(‘head’)
let meta = document.createElemnet('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
dead[0].appendChild(meta)
}
if(to.meta.title) { //路由发生变化时候修改页面中的title
document.title = to.meta.title
}
next()
})