【uniapp】根据盒子高度来设置界面高度

自认为通过获取盒子高度和手机高度来设置盒子box的高度着实有点不太高明,后面有更好的方法回来补充

uni.getSystemInfo() 获取手机系统信息

uni.createSelectorQuery() 获取节点信息,需搭配使用,

官网文档uni.createSelectorQuery() | uni-app官网 (dcloud.io)

getMenuButtonBoundingClientRect() 这个是小程序胶囊位置信息api,一起放在这好了

<template>
	<view class="box" :style="{height: fullScreen?'90vh':''}">
	  <view class="con">
		  <view class="giftCard" v-for="(item,index) in list" :key="index">
		    <!-- v-for遍历列表内容 -->
		  </view>

          <!-- 需要将foot放置到屏幕最下方 -->
		  <view class="foot">
		  	温馨提示:如有疑问请致电 4007-750-750
		  </view>
	  </view>
	</view>
</template>
async onShow() {
    //初始化list内容
	this.list = await GetUserCoupons(data)
	const userAcountInfo = await GetUserAcountInfo(data)
	await this.isShow(userAcountInfo)
    //等待list内容初始化结束之后在获取con盒子高度
	this.getPhoneInfo()
},
methods: {
	//获取手机高度和con盒子高度并且设置
	getPhoneInfo() {
		uni.getSystemInfo({
			success: res => {
				this.phoneHeight = res.screenHeight //手机高度
			}
		})
		const query = uni.createSelectorQuery().in(this);
		query.select('.con').boundingClientRect(data => {
			this.realHeight = data.height //盒子con高度
			console.log(data)
			//通过手机高度和盒子高度来判断页面是否全屏显示
			if (this.phoneHeight > this.realHeight) {
				this.fullScreen = true
			}
		}).exec()
	}
}

--------------上面的方法太蠢了

css样式有个最小高度

设置min-height: 100vh就可以了 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值