使用vue-router设置每个页面的title方法
基本环境配置: webpack + vue2.0 + vue-router +nodeJS
进入 router 文件夹底下的index.js文件
首先引入:
import Vue from 'vue' import Router from 'vue-router'
然后在路由里面配置每个路由的地址:
routes: [
{ /* (首页)默认路由地址 */
path: '/',
name: 'Entrance',
component: Entrance,
meta: {
title: '首页入口'
}
},
{ /* 修改昵称 */
path: '/modifyName/:nickName',
name: 'modifyName',
component: modifyName,
meta: {
title: '修改昵称'
}
},
{ /* 商品详情 */
path: '/goodsDetail',
name: 'goodsDetail',
component: goodsDetail,
meta: {
title: '商品详情'
}
},
{ /* Not Found 路由,必须是最后一个路由 */
path: '*',
component: NotFound,
meta: {
title: '找不到页面'
}
}
]在每一个meta里面设置页面的title名字,最后在遍历
router.beforeEach((to, from, next) => {
/* 路由发生变化修改页面title */
if (to.meta.title) {
document.title = to.meta.title
}
next()
})这样就为每一个VUE 的页面添加了title
相关推荐
前端小白 2020-07-19
bowean 2020-07-05
82344699 2020-07-05
85423468 2020-06-26
80437700 2020-05-15
80437700 2020-05-11
85423468 2020-05-05
85423468 2020-07-19
ggkuroky 2020-06-17
89711338 2020-06-14
80437700 2020-06-02
85394591 2020-05-31
85394591 2020-05-15
80324291 2020-05-11
85394591 2020-05-10
87133050 2020-04-30
85497718 2020-04-29