liveh5-nuxt/app/components/AppHeader.vue
xingyy 2d909b276b perf(components): 添加 v-memo指令以优化性能
- 在 AppFooter 组件中,为最外层 div 添加 v-memo="[active]" 指令- 在 AppHeader 组件中,为 VanNavBar 组件添加 v-memo="[title, fullLive, showLeftArrow, subTitle]" 指令
- 移除了 AppHeader 组件中的 console.log 语句
2025-01-23 15:28:31 +08:00

53 lines
1.3 KiB
Vue

<script setup>
import { useAppHeaderRouteNames as routeWhiteList } from '~/config'
import { goodStore } from "@/stores/goods/index.js";
const { fullLive } = goodStore()
const route = useRoute()
const router = useRouter()
function onBack() {
if (fullLive.value){
fullLive.value=false
return
}
if (window.history.state.back)
history.back()
else
router.replace('/')
}
const { t } = useI18n()
const title = computed(() => {
if (!route.meta)
return ''
return route.meta.i18n ? t(route.meta.i18n) : (route.meta.title || '')
})
const subTitle = computed(() => {
if (!route.meta)
return ''
return route.meta.subTitle ? t(route.meta.subTitle) : ''
})
const showLeftArrow = computed(() => route.name && routeWhiteList.includes(route.name))
</script>
<template>
<VanNavBar
v-memo="[title,fullLive,showLeftArrow,subTitle]"
:title="title"
:left-arrow="!showLeftArrow||fullLive"
placeholder clickable fixed
@click-left="onBack"
>
<template #title v-if="route.meta.i18n==='menu.goods'">
<div class="flex flex-col items-center justify-center">
<div class="text-#000000 text-17px mb-5px font-600">{{ title }}</div>
<div class="text-#939393 text-10px line-height-none font-100">{{subTitle}}</div>
</div>
</template>
</VanNavBar>
</template>