1.修改router中index.js文件中每个路由加上meta:{ title: ‘首页’}
const routes = [
{
path: '/',
name: 'home',
component: HomeView,
meta:{
title:'home页面'
}
},
{
path: '/a',
name: 'a',
component: a,
meta:{
title:'a页面'
}
},
}
2.main.js中加上
import router from './router';
router.beforeEach((to,from,next)=>{
/* 路由发生变化修改页面title */
if(to.meta.title){
document.title = to.meta.title
}
});
3.页面效果