首先我们前端在做项目时,很多高度是不能写固定的,因为我们不知道后台会有多少数据,所以我们要动态的根据不同的元素设置不同的高度,我们使用uni.getSystemInfo就能实现,在一开始onReady生命周期中调用:
1.第一种不使用箭头函数
onReady() {
// 计算屏幕剩余高度 填补剩余高度
let _this = this;
uni.getSystemInfo({
success(res) {
_this.screenHeight = res.windowHeight;
}
});
}
2.第二种使用箭头函数(看个人习惯,没有硬性要求)
onReady() {
uni.getSystemInfo({
success: (res) => {
this.screenHeight = res.windowHeight;
console.log(res.windowHeight)
}
})
}
3.获取之后就可以设置在style里了,这里使用的是对象
<view class="container" :style="{'height':screenHeight+'px'}">