美文网首页
vue-router之页面标题的动态设置

vue-router之页面标题的动态设置

作者: 时光经年 | 来源:发表于2019-03-19 20:43 被阅读0次
const router = new Router({
  routes: [
    {
      path: '/',
      name: 'index',
      meta: { title: "我是首页" },
      component: Index
    },
    {
        path:'/',
        name:'list',
        meta:{ title:"我是列表页" },
        component: List
    }
  ]
})

router.beforeEach((to, from, next) => {//beforeEach是router的钩子函数,在进入路由前执行
  if (to.meta.title) {//判断是否有标题
    document.title = to.meta.title
  }
  next()//执行进入路由,如果不写就不会进入目标页
})

export default router

相关文章

网友评论

      本文标题:vue-router之页面标题的动态设置

      本文链接:https://www.haomeiwen.com/subject/nfcomqtx.html