赞
踩
需求,在页面中,有时需要获取渲染组件的长宽信息,可以使用select
选择器进行查询,直接上代码如下:
<div ref="tabbar" id="tabbar" class="x-tabbar-wrap">
</div>
const getTabbarHeight = () => { const { windowWidth, safeAreaInsets } = <any>uni.getSystemInfoSync(); const ratio = 750 / windowWidth; safeAreaInsetsBottom.value = safeAreaInsets.bottom * ratio; // 获取组件实例 const instance = getCurrentInstance(); const query = uni.createSelectorQuery().in(instance); query .select("#tabbar") .boundingClientRect((rect) => { console.log("rect", rect); if (rect) { console.log("rect", rect); } }) .exec(); };
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。