uni-app适配布局参考

1.微信小程序+使用原生导航栏

<template>
	<view>
		<!--置顶区域-->
		<view class="head-layout">
			<!--置顶元素-->
			<view style="width: 100%;height: 100rpx;"></view>
		</view>
		<!--置顶元素相对的占位元素-->
		<view class="head-box" style="height: 100rpx;"></view>

		<!--间隔-->
		<view style="width: 100%;height:20rpx;"></view>

		<!--中间区域-->
		<view style="width: 100%;height: 2000rpx;"></view>

		<!--间隔-->
		<view style="width: 100%;height:20rpx;"></view>

		<!--置底元素相对的占位元素-->
		<view class="bot-box" style="height: 100rpx;"></view>
		<!--置底区域-->
		<view class="bot-layout">
			<!--置底元素-->
			<view style="width: 100%;height: 100rpx;"></view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {

			}
		},
		onLoad() {

		}
	}
</script>

<style lang="scss" scoped>
	.head-layout {
		width: 100%;
		position: fixed;
		top: 0;
	}

	.head-box {
		width: 100%;
	}

	.bot-layout {
		width: 100%;
		position: fixed;
		bottom: 0;
		padding-bottom: constant(safe-area-inset-bottom);
		/* 兼容 iOS < 11.2 */
		padding-bottom: env(safe-area-inset-bottom);
		/* 兼容 iOS >= 11.2 */
	}

	.bot-box {
		width: 100%;
		padding-bottom: constant(safe-area-inset-bottom);
		/* 兼容 iOS < 11.2 */
		padding-bottom: env(safe-area-inset-bottom);
		/* 兼容 iOS >= 11.2 */
	}

	/*注意:实际使用中需要根据需求调整置顶区域和置底区域的层级*/
</style>

2.微信小程序+不使用导航栏(H5+不使用导航栏)

<template>
	<view v-if="loading">
		<!--置顶区域-->
		<view class="head-layout" :style="{top:height+'px'}">
			<!--置顶元素-->
			<view style="width: 100%;height: 100rpx;"></view>
		</view>
		<!--状态栏相对的占位元素-->
		<view class="head-box" :style="{height:height+'px'}"></view>
		<!--置顶元素相对的占位元素-->
		<view class="head-box" style="height: 100rpx;"></view>

		<!--间隔-->
		<view style="width: 100%;height:20rpx;"></view>

		<!--中间区域-->
		<view style="width: 100%;height: 2000rpx;"></view>

		<!--间隔-->
		<view style="width: 100%;height:20rpx;"></view>

		<!--置底元素相对的占位元素-->
		<view class="bot-box" style="height: 100rpx;"></view>
		<!--置底区域-->
		<view class="bot-layout">
			<!--置底元素-->
			<view style="width: 100%;height: 100rpx;"></view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				height: 0,
				/*状态栏高度*/
				loading: false /*控制页面加载*/
			}
		},
		onLoad() {
			/*异步获取状态栏高度*/
			uni.getSystemInfo({
				success: (res => {
					this.height = res.statusBarHeight
					this.loading = true
				})
			})
		}
	}
</script>

<style lang="scss" scoped>
	.head-layout {
		width: 100%;
		position: fixed;
		top: 0;
	}

	.head-box {
		width: 100%;
	}

	.bot-layout {
		width: 100%;
		position: fixed;
		bottom: 0;
		padding-bottom: constant(safe-area-inset-bottom);
		/* 兼容 iOS < 11.2 */
		padding-bottom: env(safe-area-inset-bottom);
		/* 兼容 iOS >= 11.2 */
	}

	.bot-box {
		width: 100%;
		padding-bottom: constant(safe-area-inset-bottom);
		/* 兼容 iOS < 11.2 */
		padding-bottom: env(safe-area-inset-bottom);
		/* 兼容 iOS >= 11.2 */
	}

	/*注意:实际使用中需要根据需求调整置顶区域和置底区域的层级*/
</style>

3.微信小程序+自定义导航栏(H5+自定义导航栏)

<template>
	<view v-if="loading">
		<!--u-view2.0自定义导航栏,已设置固定在顶部同时生成一个等高元素防止塌陷,组件内部自动填充状态栏高度-->
		<u-navbar title="适配布局" :placeholder="true"></u-navbar>

		<!--置顶区域-->
		<view class="head-layout" :style="{top:alltop+'px'}">
			<!--置顶元素-->
			<view style="width: 100%;height: 100rpx;"></view>
		</view>
		<!--置顶元素相对的占位元素-->
		<view class="head-box" style="height: 100rpx;"></view>

		<!--间隔-->
		<view style="width: 100%;height:20rpx;"></view>

		<!--中间区域-->
		<view style="width: 100%;height: 2000rpx;"></view>

		<!--间隔-->
		<view style="width: 100%;height:20rpx;"></view>

		<!--置底元素相对的占位元素-->
		<view class="bot-box" style="height: 100rpx;"></view>
		<!--置底区域-->
		<view class="bot-layout">
			<!--置底元素-->
			<view style="width: 100%;height: 100rpx;"></view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				alltop: 0,
				/*置顶区域top值*/
				loading: false /*控制页面加载*/
			}
		},
		onLoad() {
			/*异步获取系统信息*/
			uni.getSystemInfo({
				success: (res => {
					this.alltop = res.statusBarHeight + 40
					/*常量是自定义导航栏的固定高度(不包括状态栏),需要根据实际情况调整*/
					this.loading = true
				})
			})
		}
	}
</script>

<style lang="scss" scoped>
	.head-layout {
		width: 100%;
		position: fixed;
		top: 0;
	}

	.head-box {
		width: 100%;
	}

	.bot-layout {
		width: 100%;
		position: fixed;
		bottom: 0;
		padding-bottom: constant(safe-area-inset-bottom);
		/* 兼容 iOS < 11.2 */
		padding-bottom: env(safe-area-inset-bottom);
		/* 兼容 iOS >= 11.2 */
	}

	.bot-box {
		width: 100%;
		padding-bottom: constant(safe-area-inset-bottom);
		/* 兼容 iOS < 11.2 */
		padding-bottom: env(safe-area-inset-bottom);
		/* 兼容 iOS >= 11.2 */
	}

	/*注意:实际使用中需要根据需求调整置顶区域和置底区域的层级*/
</style>

4.H5+使用原生导航栏

<template>
	<view v-if="loading">
		<!--置顶区域-->
		<view class="head-layout" :style="{top:alltop+'px'}">
			<!--置顶元素-->
			<view style="width: 100%;height: 100rpx;"></view>
		</view>
		<!--置顶元素相对的占位元素-->
		<view class="head-box" style="height: 100rpx;"></view>

		<!--间隔-->
		<view style="width: 100%;height:20rpx;"></view>

		<!--中间区域-->
		<view style="width: 100%;height: 2000rpx;"></view>

		<!--间隔-->
		<view style="width: 100%;height:20rpx;"></view>

		<!--置底元素相对的占位元素-->
		<view class="bot-box" style="height: 100rpx;"></view>
		<!--置底区域-->
		<view class="bot-layout">
			<!--置底元素-->
			<view style="width: 100%;height: 100rpx;"></view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				alltop: 0,
				/*置顶区域top值*/
				loading: false /*控制页面加载*/
			}
		},
		onLoad() {
			/*异步获取系统信息*/
			uni.getSystemInfo({
				success: (res => {
					this.alltop = res.windowTop
					this.loading = true
				})
			})
		}
	}
</script>

<style lang="scss" scoped>
	.head-layout {
		width: 100%;
		position: fixed;
		top: 0;
	}

	.head-box {
		width: 100%;
	}

	.bot-layout {
		width: 100%;
		position: fixed;
		bottom: 0;
		padding-bottom: constant(safe-area-inset-bottom);
		/* 兼容 iOS < 11.2 */
		padding-bottom: env(safe-area-inset-bottom);
		/* 兼容 iOS >= 11.2 */
	}

	.bot-box {
		width: 100%;
		padding-bottom: constant(safe-area-inset-bottom);
		/* 兼容 iOS < 11.2 */
		padding-bottom: env(safe-area-inset-bottom);
		/* 兼容 iOS >= 11.2 */
	}

	/*注意:实际使用中需要根据需求调整置顶区域和置底区域的层级*/
</style>

结论基于微信开发工具和Chrome浏览器

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值