一、配置路由器的时候添加如下项 meta
routes: [ { path: '/', name: 'login', component: Login, meta: { title: '登录' } }, { path: '/home', name: 'home', component: Home, meta: { title: '首页' } } ]
二、在main.js中写全局路由钩子
// 路由钩子 router.beforeEach((to, from, next) => { if (to.meta.title) { document.title = to.meta.title } next() })
这样就可以在路由跳转的时候修改响应界面的title值了。