-
需求
实现切换路由时,标签页显示的 title 会根据不同页面发生改变 -
实现
(1)在路由配置页面 (src/router/index.js)中,给每项路由(routes)配置添加路由元信息 meta ,如:{ path: '/news', name: 'news', component: news, meta: { title: '公司新闻' } }(2)在入口 js 文件 — main.js 中,配置路由守卫,监视路由变化:
router.beforeEach((to, from, next) => { if (to.meta.title) { document.title = to.meta.title } next() })
来源:CSDN
作者:"Zero'_
链接:https://blog.csdn.net/weixin_44731536/article/details/103984810