soonfy / issue-blog

blog using issue
0 stars 0 forks source link

vue 设置 title #56

Open soonfy opened 6 years ago

soonfy commented 6 years ago

固定 title

const router = new Router({
  mode: 'history',
  base: process.env.BASE_URL,
  routes: [
    {
      path: '/index',
      name: 'index',
      component: () => import(/* webpackChunkName: "about" */ './views/Index.vue'),
      meta: {
        title: '首页'
      }
    }]
})
router.beforeEach((to, from, next) => {
  /* 路由发生变化修改页面title */
  console.log(to)
  if (to.meta.title) {
    document.title = to.meta.title
  } else {
    document.title = '默认title'
  }
  next()
})

异步设置 title

async loadData(id) {
  let data = await this.$http.get(`/${id}/`)
  document.title = data.name
}

soonfy

soonfy commented 6 years ago

22 vue-router 动态设置页面 title