贴代码:
想每次进一个路由的时候,改一下document.title
import Vue from 'vue'import Router from 'vue-router'Vue.use(Router) const router = new Router({ routes: [ //首页 { path: '/', name: 'index', component: () => import('../components/index.vue'), meta: { title: '首页' } }, //详情页 { path: '/detail', name: 'Detail', component: () => import('../components/Detail.vue'), meta: { title: '详情页' } } ] }); router.beforeEach((to, from, next) => { if(to.meta.title) { document.title = to.meta.title; } });export default router
去掉router.beforeEach之后,router-view就出现了,然后document.title没改,
加回router.beforeEach之后,router-view就消失了,然后document.title改了。
波斯汪
相关分类