<view class="page-box">
<view class="fixed-box"></view>
<scroll-view :style="{height:scrollHeight}" scroll-y="true"></scroll-view>
</view>
需求:根据屏幕的高度和fixed-box的高度计算scroll-view的高度
<script lang="ts" setup>
const scrollHeight = ref('')
const calculateHeight = ()=>{
let windowHeight = null
let fixedHeight = 0
let paginationHeight = 0
uni.getSystemInfo({ //获取屏幕高度
success: res => {
console.log("屏幕高度:", res.windowHeight) //res.windowHeight是返回的屏幕高度
windowHeight = res.windowHeight;
}
});
// 获取元素高度
let query = uni.createSelectorQuery().in(instance);
query.select('.fixed-box').boundingClientRect();
query.exec(res => {
console.log('元素高度',res[0].height)// 返回的值可以用作动态修改元素的高度
fixedHeight = res[0].height;
});
scrollHeight.value = windowHeight - fixedHeight + 'px'
}
</script>