私域电商软件及相关增值服务提供商    

免费试用
2023年微信小程序API-设备-系统信息
作者: --时间: 2025-07-12 02:37:08 阅读量:

您是否想知道如何获取手机型号、屏幕宽高以及微信版本号等系统信息?微信小程序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电商交易系统

上下游资源整合数字化解决方

了解更多
企业集采商城系统

中大型企业数字化采购与交易
系统

了解更多
员工福利商城系统

集福利管理、发放于一体的员
工福利商城

了解更多

电话咨询 微信咨询 0元开店