需求,在页面中,有时需要获取渲染组件的长宽信息,可以使用select
选择器进行查询,直接上代码如下:文章来源地址https://www.toymoban.com/news/detail-601860.html
<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();
};
文章来源:https://www.toymoban.com/news/detail-601860.html
到了这里,关于uniapp小程序vue3获取dom实例createSelectorQuery的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!