实时修改title

路由

const router = new Router({
  mode: 'history',
  routes: [
    {
      path: '/index',
      name: 'index',
      component: Index,
      meta:{
        // 页面标题title
        title: '首页'
      }
    },
    {
      path: '/content',
      name: 'content',
      component: Content,
      meta:{
        title: '内容'
      }
    }
  ]
})
export default router

main.js

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

 

posted @ 2019-06-04 11:15  ronle  阅读(245)  评论(0编辑  收藏  举报