app.js
// app.js App({ onLaunch(e) { // 判断屏幕大小 var judgeBigScreen = () => { let result = false; const res = wx.getSystemInfoSync(); const rate = res.windowHeight / res.windowWidth; let limit = res.windowHeight == res.screenHeight ? 1.8 : 1.65; // 临界判断值 if (rate > limit) result = true; return result; } this.globalData.judgeBigScreen = judgeBigScreen(); }, globalData: { judgeBigScreen:false, } })
定义好之后在需要判断的页面使用即可
var app = getApp() Page({ data: { }, onLoad(options) { console.log('是否为长屏', app.globalData.judgeBigScreen); }, })