sunniejs / vue-h5-template

:tada:vue搭建移动端开发,基于vue-cli4.0+webpack 4+vant ui + sass+ rem适配方案+axios封装,构建手机端模板脚手架
https://sunniejs.github.io/vue-h5-template/
MIT License
3.09k stars 875 forks source link

如何在vue页面里修改title标题 #36

Closed hugeng1979 closed 2 years ago

hugeng1979 commented 3 years ago

首先,非常感谢你的项目。让我从vue新手能开始简单的写页面了。 有个问题想咨询一下,如何在类似about.vue里,修改最外面的title。

path: '/about', name: 'About', component: () => import('@/views/home/about'), meta: { title: '关于我', keepAlive: false } 这里的title配置不起作用。

hugeng1979 commented 3 years ago

解决了。我在router/index.js 增加了

const defaultTitle = '默认 title' router.beforeEach((to, from, next) => { document.title = to.meta.title ? to.meta.title : defaultTitle next() })

sunniejs commented 3 years ago

感谢您的使用,希望能为我的项目提供更多的意见和使用建议,为他人提供宝贵的意见,比心