Skip to content

Commit

Permalink
feat: 动态标题支持
Browse files Browse the repository at this point in the history
  • Loading branch information
markthree committed May 9, 2022
1 parent efed550 commit 52a8b7a
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 3 deletions.
2 changes: 1 addition & 1 deletion .env
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# 通用环境变量

# 标题
VITE_APP_TITLE = Vite App 🎉
VITE_APP_TITLE = tov


# markdown 渲染支持
Expand Down
2 changes: 1 addition & 1 deletion .env.development
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# 开发时环境变量

# 标题
# VITE_APP_TITLE = Vite App 🎉
# VITE_APP_TITLE = tov


# 开发时 Inspect 调试支持
Expand Down
2 changes: 1 addition & 1 deletion .env.production
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# 生产时环境变量

# 标题
# VITE_APP_TITLE = Vite App 🎉
# VITE_APP_TITLE = tov


# 生产时 mock 支持
Expand Down
9 changes: 9 additions & 0 deletions src/modules/title.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { router } from './router'

const title = useTitle(import.meta.env.VITE_APP_TITLE)

router.beforeEach((r) => {
const originTitle = import.meta.env.VITE_APP_TITLE
const name = r.name?.toString().toLowerCase()
title.value = name === 'index' ? originTitle : `${originTitle} | ${name}`
})

0 comments on commit 52a8b7a

Please sign in to comment.