«

vue2修改标题

emer 发布于 2018-10-8 10:33   2335 次阅读     


main.js中:

router.beforeEach((to, from, next) => {
  console.log();
  /* 路由发生变化修改页面title */
  if (to.meta.title) {
    console.log(1);
    document.title = to.meta.title;
  }
  next();
})
route.js中:

 routes: [
    {
      path: '/login',
     name:"login",
     meta:{
       title:"登录"
     },
     component:Login
    },{
      path:'/index',
      name: 'index',
       meta:{
       title:"覆手为雨-VR"
     },
            component: index
    },{
      path:'/',
      name:"artIndex",
       meta:{
       title:"覆手为雨"
     },
      component:artIndex
    }
  ]