router.js
{ path: '/nav', component: () => import('../view/nav.vue'), meta:{ title:'nav', } }, { path: '/haha', component: () => import('../view/haha.vue'), meta:{ title:'haha' } }
main.js中
router.beforeEach((to, from, next) => { /* 路由发生变化修改页面meta */ if(to.meta.content){ let head = document.getElementsByTagName('head'); let meta = document.createElement('meta'); meta.content = to.meta.content; head[0].appendChild(meta) } /* 路由发生变化修改页面title */ if (to.meta.title) { document.title = to.meta.title; } next() });
ok
喜欢的小伙伴可以关注我的微信公众号“前端伪大叔”