vue路由跳转更改页面title

1.在路由数组设置里加meta对象

const routes = [
    { path: '/workReport',
      component: WorkReport,
      meta: {
          title: '往期日报'
      }
    }
]

const router = new VueRouter({
    routes
})

2.做如下配置

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

 

posted @ 2019-03-02 19:45  wayne529  阅读(4035)  评论(0编辑  收藏  举报