export default {
getSystemInfo(key) {
return new Promise(function(resolve, reject) {
uni.getSystemInfo({
success(res) {
key ? resolve(res[key]) : resolve(res)
}
})
})
},
getDomHeight(_this, selector) {
return new Promise(function(resolve, reject) {
const query = uni.createSelectorQuery().in(_this);
query.select(selector).boundingClientRect(data => {
resolve(data.height)
}).exec();
})
},
async getScrollViewHeight(_this, arr) {
let height = 0
let windowHeight = await this.getSystemInfo('windowHeight')
for (let i = 0; i < arr.length; i++) {
let h = await this.getDomHeight(_this, arr[i])
height += h
}
return windowHeight - height
}
}
// 在页面中使用 , this是当前页面中的this, arr 是包含dom类名的数组
async onReady() {
// 顶部搜索栏 和 轮播图 的类名
let arr = ['.search-block','.swiper-block']
this.height = await scrollView.getScrollViewHeight(this, arr)
},
- height 最好给个默认值 height:300,不为0即可
- scroll-view 标签上 动态绑定 height :style=" 'height:'+height+'px;' "
<scroll-view :style="'height:'+ height + 'px;'" scroll-y="true" @scrolltolower="scrollToLower">
<view v-for="(item,index) in list" :key="index" ></view>
</scroll-view>
网友评论