uniapp 获取屏幕分辨率
uni-app提供了异步(uni.getSystemInfo
)和同步(uni.getSystemInfoSync
)的2个API获取系统信息。
具体使用:
//data声明变量 windowWidth windowHeight //created 获取信息 uni.getSystemInfo({ success: (res) => { this.windowWidth = res.windowWidth; this.windowHeight = res.windowHeight; console.log("宽度:", this.windowWidth); console.log("高度:", this.windowHeight); }, });
返回的数据:
{ "SDKVersion": "", "appId": "__UNI__7230821", "appLanguage": "zh-Hans", "appName": "测试实例", "appVersion": "1.0.0", "appVersionCode": 101, "appWgtVersion": "1.0.0", "brand": "huawei", "browserName": "chrome", "browserVersion": "88.0.4324.93", "deviceBrand": "huawei", "deviceId": "823d3fbfe01e3ed6", "deviceModel": "WGR-W09", "deviceOrientation": "landscape", "devicePixelRatio": 2, "deviceType": "pad", "errMsg": "getSystemInfo:ok", "language": "zh-CN", "model": "WGR-W09", "osAndroidAPILevel": 29, "osLanguage": "zh-CN", "osName": "android", "osTheme": "light", "osVersion": "10", "pixelRatio": 2, "platform": "android", "romName": "HarmonyOS", "romVersion": "2.0.0", "safeArea": { "left": 0, "right": 1280, "top": 24, "bottom": 800, "width": 1280, "height": 776 }, "safeAreaInsets": { "top": 24, "right": 0, "bottom": 0, "left": 0 }, "screenHeight": 800, "screenWidth": 1280, "statusBarHeight": 24, "system": "Android 10", "ua": "Mozilla/5.0 (Linux; Android 10; WGR-W09 Build/HUAWEIWGR-W09; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/88.0.4324.93 Safari/537.36 uni-app (Immersed/24.0)", "uniCompileVersion": "3.4.15", "uniPlatform": "app", "uniRuntimeVersion": "3.4.15", "version": "1.9.9.81354", "windowBottom": 0, "windowHeight": 800, "windowTop": 0, "windowWidth": 1280 }
uniapp官网:系统信息 uni.getSystemInfo