From 702d65ef47a01300a40d28c63be2ea02ae72c521 Mon Sep 17 00:00:00 2001 From: Frost-ZX Date: Thu, 29 Aug 2024 14:46:06 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E5=8A=A8=E6=80=81=E6=9B=B4=E6=96=B0?= =?UTF-8?q?=E9=A1=B5=E9=9D=A2=E6=A0=87=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/assets/js/utils.js | 9 +++++++++ src/router/index.js | 8 ++++++++ 2 files changed, 17 insertions(+) create mode 100644 src/assets/js/utils.js diff --git a/src/assets/js/utils.js b/src/assets/js/utils.js new file mode 100644 index 0000000..78a6d8f --- /dev/null +++ b/src/assets/js/utils.js @@ -0,0 +1,9 @@ +import { description as appDesc } from '@package-json'; + +/** + * @description 更新页面标题 + * @param {string} title + */ +export function updateAppTitle(title = '') { + document.title = (title ? `${title} - ${appDesc}` : appDesc); +} diff --git a/src/router/index.js b/src/router/index.js index 0b369a4..60ab725 100644 --- a/src/router/index.js +++ b/src/router/index.js @@ -3,6 +3,10 @@ import { createWebHashHistory, } from 'vue-router'; +import { + updateAppTitle, +} from '@/assets/js/utils'; + import { ENABLE_SEARCH_MODULE, ENABLE_NAV_MODULE, @@ -67,3 +71,7 @@ export const router = createRouter({ }, ], }); + +router.afterEach((to) => { + updateAppTitle(to.meta.title); +});