赞
踩
uni.getSystemInfo(OBJECT)
uni.getSystemInfoSync()
<template>
<view class="content">
<view style="background-color: red;" :style="{height:heightOne+'px'}">1</view>
<view style="background-color: yellow;" :style="{height:heightTwo+'px'}">2</view>
</view>
</template>
<script>
export default{
data(){
return{
heightOne:0,
heightTwo:0,
}
},
onReady(){
const self = this;
switch (uni.getSystemInfoSync().platform) {
case 'ios':
// 异步方式
uni.getSystemInfo({
success: function (res) {
console.log(res.safeArea)
self.heightOne = res.safeArea.top;//头部区域
self.heightTwo = res.safeArea.height;//内容区域
}
});
//同步方式
// self.heightOne.uni.getSystemInfoSync().safeArea.top
// self.heightTwo.uni.getSystemInfoSync().safeArea.height
break;
}
},
onLoad(){
},
onShow() {
},
methods:{
}
}
</script>
<style>
</style>
结果如下:
<template>
<view class="content">
<view class="contents" :style="{bottom:heightOne+'px'}">
</view>
</view>
</template>
<script>
export default{
data(){
return{
heightOne:0,
heightTwo:0,
}
},
onReady(){
const self = this;
switch (uni.getSystemInfoSync().platform) {
case 'ios':
// 异步方式
uni.getSystemInfo({
success: function (res) {
console.log(res.safeArea)
let sHeight = res.screenHeight;//获取屏幕高度
let sTop = res.safeArea.bottom;//获取安全区域底部高度
self.heightOne = sHeight - sTop;//获取安全区域距离底部的高度
}
});
//同步方式
// self.heightOne.uni.getSystemInfoSync().safeArea.top
// self.heightTwo.uni.getSystemInfoSync().safeArea.height
break;
}
},
onLoad(){
},
onShow() {
},
methods:{
}
}
</script>
<style>
.contents{
background-color: red;
position: absolute;
width: 100%;
height: 10rpx;
}
</style>
结果如下:
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。