diff --git a/src/components/lx-header/lx-header.vue b/src/components/lx-header/lx-header.vue index 84e41be1203b701953f5b134fe25a1e049d807ae..866c9b719f4d6975bcc88d25fb0f0262c0d87fc6 100644 --- a/src/components/lx-header/lx-header.vue +++ b/src/components/lx-header/lx-header.vue @@ -8,7 +8,7 @@ * @version: V1.0.2 */ import { goToPage } from '@/utils/util' -import { ref, watchEffect, type CSSProperties } from 'vue' +import { getCurrentInstance, type CSSProperties } from 'vue' // 引入tabbar import useTabbarInfo from '@/store/tabbar' @@ -95,6 +95,16 @@ const goBack = () => { uni.navigateBack() } } +onMounted(() => { + const query = uni.createSelectorQuery().in(getCurrentInstance()) + query + .select('.header_box') + .boundingClientRect((data) => { + let newdata = JSON.parse(JSON.stringify(data)) + tabbarInfo.setHeaderHeight(Math.round(newdata.height)) + }) + .exec() +}) diff --git a/src/store/tabbar.ts b/src/store/tabbar.ts index 57b8bb33467600add0142dddd3120a128316245b..b27698d7d443a919ec3a737c27738fceacd976ff 100644 --- a/src/store/tabbar.ts +++ b/src/store/tabbar.ts @@ -3,6 +3,11 @@ import { getPrefixName } from '@/config' import type { menuListInt } from '@/components/lx-tabbar/type' export default defineStore(getPrefixName('tabbar'), () => { + // 头部高度 + const headerHeight = ref(0) + function setHeaderHeight(num: number) { + headerHeight.value = num + } // tabbar选中项name const selectTabbarName = ref('home') // 循环的导航项 @@ -50,6 +55,8 @@ export default defineStore(getPrefixName('tabbar'), () => { selectTabbarName, menuList, clickTabbar, - tabbarChangeIndex + tabbarChangeIndex, + headerHeight, + setHeaderHeight } })