1、在vue中路由的meta添加自定义对象

12abc5e011b1ee835e88733787e380f1.png

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()
})
Logo

前往低代码交流专区

更多推荐