美文网首页
scroll-view通过query获取高度的问题

scroll-view通过query获取高度的问题

作者: flyjar | 来源:发表于2021-07-30 10:12 被阅读0次
<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
});

相关文章

网友评论

      本文标题:scroll-view通过query获取高度的问题

      本文链接:https://www.haomeiwen.com/subject/hcmqvltx.html