vue设置页面title
src/router/index.jsimport Vue from 'vue';import Router from 'vue-router';Vue.use(Router);const router = new Router({routes: [{name: 'home',path: '/',m...
·
src/router/index.js
import Vue from 'vue';
import Router from 'vue-router';
Vue.use(Router);
const router = new Router({
routes: [{
name: 'home',
path: '/',
meta: {
title: '首页'
},
component: Home
},
{
name: 'productList',
path: '/productList',
meta: {
title: '商品列表'
},
component: ProductList
},
{ /* 404必须是最后一个路由 */
name: '404',
path: '*',
meta: {
title: '找不到页面'
},
component: NotFound
}
]
});
router.beforeEach((to, from, next) => {
/* 路由发生变化修改页面title */
if (to.meta.title) {
document.title = to.meta.title;
}
next();
});
export default router;
更多推荐
已为社区贡献24条内容
所有评论(0)