在index.js页面中设置路由跳转中加上meta,然后利用vue的beforeEach遍历设置每个页面的title
亲测有效
const router=new Router({
routes: [
{
path: '/',
name: 'goods',
component: goods,
meta: {
title: '首页入口'
}
},{
path:'/ratings',
name:'ratings',
component:ratings,
meta: {
title: '评论'
}
},{
path:'/seller',
name:'seller',
component:seller,
meta: {
title: '售卖'
}
}
]
})
router.beforeEach((to,form,next) =>{
/*路由变化修改title*/
if(to.meta.title){
document.title=to.meta.title
}
next();
})
export default router