我们用的是路由守卫
首先我们在router > index.vue
这个文件中
给所有的配置好的路由添加一个 meta属性
{
path: '/',
name: 'Home',
component: Home,
meta:{
"title":"首页"
}
},
{
path: '/list',
name: 'List',
component: List,
meta:{
"title":"关于"
}
},
然后在倒数第二行写上就可以了
router.beforeEach( (to,from,next) => {
if(to.meta.title){
document.title = to.meta.title
}
next()
})
如果是移动端
可以用
{{$route.meta.title}}
获取相应的标题