uniapp开发小程序,使用uview组件库,获取自定义tabbar组件高度。

uview中获取自定义tabbar组件高度

业务场景
  • tabbar动态内容,各页面独立tabbar
  • 多选框吸附底部tabbar,适配不同设备
技术实现方案
  • 获取u-tabbar组件高度,多选框动态样式绑定
  • 上代码
# 多选框动态样式绑定
<view class="checked_all" :style="{bottom:onReachBottom + 'px'}">
	<u-checkbox-group>
		<u-checkbox label='全选' :checked="isAllChecked" shape="circle" @change="allChoose">
		</u-checkbox>
	</u-checkbox-group>
	<view class="btn">
		<u-button color="linear-gradient( 270deg, #19D380 0%, #0CBBAA 100%)" shape="circle" text="处理"></u-button>
	</view>
</view>
# 组件加载完成后获取元素高度
onReady() {
			const query = uni.createSelectorQuery().in(this.$refs.customTabBar);
			query
				.select("#customTabBar >>> .u-tabbar__content")//跨自定义组件的后代选择器
				.boundingClientRect((data) => {
					console.log("得到布局位置信息", data);
					this.onReachBottom = data.height
				})
				.exec();
		},
# 自定义tabbar组件
<template>
	<u-tabbar id="customTabBar" :value="currentTab" @change="switchTab" inactiveColor="#A1A1A1" activeColor="#333333">
		<u-tabbar-item :text="item.name" v-for="item,index in list" :key="index">
			<image class="tabbar-cion" slot="active-icon" :src="config.ossUrl + item.activeIcon">
			</image>
			<image class="tabbar-cion" slot="inactive-icon" :src="config.ossUrl +item.inactiveIcon"></image>
		</u-tabbar-item>
	</u-tabbar>
</template>

效果图如下

![请添加图片描述](https://i-blog.csdnimg.cn/direct/d081b619f29d4f53a15ebec9a462e510.png请添加图片描述

  • 使用uni.createSelectorQuery() 获取 u-tabbar组件高度时需要选择.u-tabbar-content类名 ,.u-tabbar获取节点信息会返回null,使用.u-tabbar__placeholder类名可能是渲染问题高度会返回0,需要加定时器延时才能获取真实高度。
  • 经测试,iPhone、安卓无底部虚拟按键、有虚拟按键下都可实现吸附效果。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值