松果果

  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

router.js 参考如下

Vue.use(VueRouter);

const routes = [
    {
        path: "/",
        component: index,
        name: "index",
        meta: {
            title: '首页'
        }
    }]
var router = new VueRouter({
    routes
})

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

前提条件

确保vue项目的index.html文件中有

<title><%= htmlWebpackPlugin.options.title %></title>

默认vue cli是有这行代码的

补充

你也可以直接在你的业务页面修改标题

//在业务页面修改标题
document.title = "标题名称";
posted on 2020-10-20 20:05  松果果  阅读(3058)  评论(0编辑  收藏  举报