1.app.js里面
//获取状态栏的高度
wx.getSystemInfo({
success: function (res) {
that.globalData.statusBarHeight = res.statusBarHeight;
}
})
2.注意:that需要在方法里面,比如 onLaunch: function ()里面定义var that = this
3.页面的js里面
const app = getApp();
data: {
//获取全局变量 导航栏的高度statusBarHeight
statusBarHeight: getApp().globalData.statusBarHeight,
},
4.页面里面
<view class="status-bar" style='height: {{statusBarHeight}}px;'></view>