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

猜你喜欢

转载自www.cnblogs.com/lw5116/p/10462587.html