美文网首页web 前端前端
vue设置页面标题title

vue设置页面标题title

作者: lesdom | 来源:发表于2018-08-18 01:25 被阅读0次

每个页面设置相同标题

index.html

直接修改title标签里面的标题
(ps: 这个html文件中也可以引入一些js文件)

每个页面设置不同标题

router - index.js

const router = new Router({
    mode: 'history',
    routes: [
        {
            path: '/index',
            name: 'index',
            component: Index,
            meta:{
                // 页面标题title
                title: '首页'
            }
        },
        {
            path: '/content',
            name: 'content',
            component: Content,
            meta:{
                title: '内容'
            }
        }
    ]
})
export default router

main.js

import router from './router'
router.beforeEach((to, from, next) => {
  /* 路由发生变化修改页面title */
  if (to.meta.title) {
    document.title = to.meta.title
  }
  next()
})

网站导航

网站导航

相关文章

网友评论

    本文标题:vue设置页面标题title

    本文链接:https://www.haomeiwen.com/subject/wtyxiftx.html