scroll-view通过query获取高度的问题
2021-07-30 本文已影响0人
flyjar
<template>
<scroll-view id="scrollview" scroll-y="true" :style="{height:scrollHeight+'px'}" :scroll-top="scrollTop"
</scroll-view>
</template>
如果scroll-view外层没有view或者其他元素包住的话,query查询的话会是null
let query = uni.createSelectorQuery().in(this)
query.select('#scrollview').boundingClientRect()
query.exec((res) => {
//res会是null
});
<template>
<view>
<scroll-view id="scrollview" scroll-y="true" :style="{height:scrollHeight+'px'}" :scroll-top="scrollTop"
</scroll-view>
</view>
</template>
如果scroll-view外层有内容包住之后,query才能查询出来信息
let query = uni.createSelectorQuery().in(this)
query.select('#scrollview').boundingClientRect()
query.exec((res) => {
//res会是null
});