feat(router): 优化服务页面标题显示并添加网页标题动态设置

- 在路由配置中为服务页面添加 meta 标题属性
- 修改布局组件,根据路由参数动态显示页面标题
- 添加网页标题动态设置,与页面内标题保持一致
This commit is contained in:
huangze
2025-07-07 19:16:03 +08:00
parent 5277ac5e20
commit 00014633b2
3 changed files with 23 additions and 9 deletions

View File

@@ -40,6 +40,9 @@ export default [
{
path: '/service/:ecosystem',
name: 'service',
meta:{
title: '服务'
},
component: () => import('@/views/service/service-t.vue')
},
{

View File

@@ -1,10 +1,10 @@
<template>
<div class="layout-container">
<van-nav-bar :title="title" left-arrow @click-left="handleNavbarLeftClick" class="nav">
<!-- <van-nav-bar :title="title" left-arrow @click-left="handleNavbarLeftClick" class="nav">
<template #right>
<van-icon name="ellipsis" size="18" />
</template>
</van-nav-bar>
</van-nav-bar> -->
<router-view />
</div>
</template>
@@ -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: {

View File

@@ -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()
}
}
</script>