Allen's blog Allen's blog
首页
面经
算法 (opens new window)
分类

Allen

前端CV工程师
首页
面经
算法 (opens new window)
分类
  • Javascript

  • TypeScript

  • CSS

  • Vue

  • React

  • 框架和构建工具

  • 工具库

  • 常见业务场景

  • Bug

  • 项目实战

    • 飞书多维表格React项目

    • tj-school-vue2

      • 每个页面配置新的页面title
      • 自适应不同屏幕尺寸
    • my-linter

    • chrome-extension

    • 特征采集系统electron

  • 前端
  • 项目实战
  • tj-school-vue2
Allen
2023-05-09

每个页面配置新的页面title

设置 title 的方式是采用 js 给 document.title 赋值。

可以在路由守卫的地方给每个页面设置 title。

import Vue from 'vue'
import VueRouter from 'vue-router'
import HomeIndex from '@/pages/home/index.vue'

Vue.use(VueRouter)

const router = new VueRouter({
    mode: 'history',
    base: import.meta.env.BASE_URL,
    routes: [
        {
            path: '/',
            name: 'home',
            meta: { title: 'xxxxxx' },
            component: HomeIndex
        },
        {
            path: '/activity',
            name: 'activity',
            meta: { title: 'xxxxxxx' },
            component: () => import('@/pages/activity/index.vue')
        }
    ]
})

router.beforeEach((to, from, next) => {
    if (to.meta.title) {
        document.title = to.meta.title
    }
    next()
})

export default router
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
上次更新: 2023/12/16, 09:22:46
tailwind+mantine写UI
自适应不同屏幕尺寸

← tailwind+mantine写UI 自适应不同屏幕尺寸→

最近更新
01
rollup使用配置文件rollup.config.ts打包
12-08
02
package.json导出类型
12-08
03
关键问题方案
11-17
更多文章>
Theme by Vdoing | Copyright © 2023-2023 Allen | Github
  • 跟随系统
  • 浅色模式
  • 深色模式
  • 阅读模式