From 00014633b2f8507636b82b3548226d8604bc8569 Mon Sep 17 00:00:00 2001 From: huangze Date: Mon, 7 Jul 2025 19:16:03 +0800 Subject: [PATCH] =?UTF-8?q?feat(router):=20=E4=BC=98=E5=8C=96=E6=9C=8D?= =?UTF-8?q?=E5=8A=A1=E9=A1=B5=E9=9D=A2=E6=A0=87=E9=A2=98=E6=98=BE=E7=A4=BA?= =?UTF-8?q?=E5=B9=B6=E6=B7=BB=E5=8A=A0=E7=BD=91=E9=A1=B5=E6=A0=87=E9=A2=98?= =?UTF-8?q?=E5=8A=A8=E6=80=81=E8=AE=BE=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 在路由配置中为服务页面添加 meta 标题属性 - 修改布局组件,根据路由参数动态显示页面标题 - 添加网页标题动态设置,与页面内标题保持一致 --- src/router/app/index.js | 3 +++ src/views/app/layout/Layout.vue | 14 ++++++++++---- src/views/home/home.vue | 15 ++++++++++----- 3 files changed, 23 insertions(+), 9 deletions(-) diff --git a/src/router/app/index.js b/src/router/app/index.js index 1eca68c..a5b1cae 100644 --- a/src/router/app/index.js +++ b/src/router/app/index.js @@ -40,6 +40,9 @@ export default [ { path: '/service/:ecosystem', name: 'service', + meta:{ + title: '服务' + }, component: () => import('@/views/service/service-t.vue') }, { diff --git a/src/views/app/layout/Layout.vue b/src/views/app/layout/Layout.vue index 5fbf7bf..6328ab0 100644 --- a/src/views/app/layout/Layout.vue +++ b/src/views/app/layout/Layout.vue @@ -1,10 +1,10 @@ @@ -20,11 +20,17 @@ export default { computed: { title() { const name = this.$route.name + let title = this.$route.meta.title if (name === "service") { const ecosystem = this.$route.params.ecosystem - return getAlias(getEcosystem(ecosystem)) + title = getAlias(getEcosystem(ecosystem)) } - return this.$route.meta.title + return title + } + }, + watch:{ + $route(to, from){ + document.title = this.title } }, methods: { diff --git a/src/views/home/home.vue b/src/views/home/home.vue index 6053f4f..3f9701d 100644 --- a/src/views/home/home.vue +++ b/src/views/home/home.vue @@ -50,6 +50,13 @@ export default { swe: swe } }) + }, + showErrorDialog() { + Dialog({ + message: '页面访问有误,请重试', + }).then(() => { + this.$router.go(-1) + }) } }, mounted() { @@ -62,13 +69,11 @@ export default { this.name = content.name this.sex = Number(content.sex) this.type = Number(content.type) + }).catch(() => { + this.showErrorDialog() }) } - else Dialog({ - message: '页面访问有误,请重试', - }).then(() => { - this.$router.go(-1) - }) + else this.showErrorDialog() } }