Vue-touter的全局守卫的使用,设置页面的动态标题

1.在router的index.js配置映射关系中添加meta:{title:'首页'};

{
    path:'/profile',
    component:Profile,
    meta:{
    title:'个人'
 }

2、使用 router.beforeEach方法:

router.beforeEach( (to,from,next) => {
  document.title = to.matched[0].meta.title
  next();
})

  

  

posted @ 2020-12-11 11:31  银河游鱼  阅读(110)  评论(0编辑  收藏  举报