2023年微信小程序API-设备-系统信息
您是否想知道如何获取手机型号、屏幕宽高以及微信版本号等系统信息?微信小程序API中的设备-系统信息可以帮您实现这些功能。
1. wx.getSystemInfo(OBJECT)
通过调用wx.getSystemInfo()方法,我们可以获取到各种关于系统的信息。需要注意的是,为了保证取到数据,我们需要传递OBJECT参数,并在其中添加success、fail和complete回调函数。其中success回调函数可返回系统信息,常用数据如下:
参数 | 说明 |
---|---|
model | 手机型号 |
pixelRatio | 设备像素比 |
system | 操作系统版本 |
version | 微信版本号 |
screenWidth | 屏幕宽度 |
screenHeight | 屏幕高度 |
windowWidth | 可使用窗口宽度 |
windowHeight | 可使用窗口高度 |
示例代码:
wx.getSystemInfo({
success: function(res) {
console.log(res.model);
console.log(res.pixelRatio);
console.log(res.windowWidth);
console.log(res.windowHeight);
console.log(res.version);
console.log(res.system);
}
});
2. wx.getSystemInfoSync()
与wx.getSystemInfo()的区别是,wx.getSystemInfoSync()为同步接口获取系统信息,无需传递回调函数。同样,返回的常用数据有:
参数 | 说明 |
---|---|
model | 手机型号 |
pixelRatio | 设备像素比 |
system | 操作系统版本 |
version | 微信版本号 |
screenWidth | 屏幕宽度 |
screenHeight | 屏幕高度 |
windowWidth | 可使用窗口宽度 |
windowHeight | 可使用窗口高度 |
示例代码:
try {
var res = wx.getSystemInfoSync();
console.log(res.model);
console.log(res.pixelRatio);
console.log(res.windowWidth);
console.log(res.windowHeight);
console.log(res.version);
console.log(res.system);
} catch (e) {
// Do something when catch error
}
3. wx.canIUse(String)
通过调用wx.canIUse()方法,我们可以判断当前版本是否支持小程序API、回调、参数、组件等。需要注意的是,String参数需要以"${API}.${method}.${param}.${options}"或者"${component}.${attribute}.${option}"方式来调用。
举
-
B2B2C多用户商城系统支持企业自营与商户入驻模式共存 会员一站式精细化营销工具 多用户分销,带来爆发式增长
系统支持平台自营+供应商店铺共存的经营模式(类天猫&京东模式),帮助企业打造生态级商业平台为目的的电子商务系统。
免费试用系统 -
B2B2B电商交易系统优化供应链协作 授信及账期支付 商品按照数量阶梯设价
全渠道订货/采购及经销商管理数字化系统,实现供应链整合和交易便捷化。
免费试用系统 -
S2B2B电商交易系统供销一体化,提高市场集中度 集团管控一体化,有效实现供需匹配 移动应用一体化,提高运营综合效率
上下游资源整合数字化解决方案,赋能产业供应链,构建产业互联网生态体系。
免费试用系统
