uniapp通过id获取dom的宽度,高度,位置等( 任意平台都通用 )
javascript
<template>
<view class="" id="domId"></view>
</template>
// 如果获取的dome高度等不对,还需要加上延迟setTimeout(()=>{ }, 100)
this.$nextTick(() => {
const query = uni.createSelectorQuery().in(this);
query
.select('#domId')
.boundingClientRect((dome) => {
console.log(dome)
})
.exec();
})
console.log打印的值
javascript
{
"id": "domId",
"dataset": {},
"left": 0,
"right": 484,
"top": 0,
"bottom": 282,
"width": 484,
"height": 282
}