vue 設置動態標題

1.router/index.js

export default new Router({
  mode:'history',
  routes: [
    {
      path: '/',
      name: 'HelloWorld',
      component: HelloWorld,
      meta:{
        title: '首頁'
      }
    }
  ]
})

2.main.js

router.beforeEach((to,from,next) => {
/* 路由發生變化修改頁面title */
  if(to.meta.title){
    document.title = to.meta.title
  }
  next()
});
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章