本文编辑: 技术蓝天浏览 5353
版权所有,严禁转载
获取系统信息接口和获取系统同步信息接口。
| 接口 | 说明 |
|---|---|
| wx.getSystemInfo(OBJECT) | 获取系统信息。 |
| wx.getSystemInfoSync() | 获取系统信息同步接口 |

【代码】
wxml
<button type="default" bindtap="getSystemInfo">获取系统信息</button>
<button type="primary" bindtap="getSystemInfoSync">获取系统信息同步</button>
js
getSystemInfo : function(){
wx.getSystemInfo({
success: function(res) {
console.log(res.model)
console.log(res.pixelRatio)
console.log(res.windowWidth)
console.log(res.windowHeight)
console.log(res.language)
console.log(res.version)
console.log(res.platform)
}
})
}

【代码】
wxml
<button type="default" bindtap="getSystemInfo">获取系统信息</button>
<button type="primary" bindtap="getSystemInfoSync">获取系统信息同步</button>
js
getSystemInfoSync : function(){
var res = wx.getSystemInfoSync()
console.log(res.model)
console.log(res.pixelRatio)
console.log(res.windowWidth)
console.log(res.windowHeight)
console.log(res.language)
console.log(res.version)
console.log(res.platform)
}
【wx.getSystemInfo(OBJECT)】:【获取系统信息。】
【方法内容描述】
| 参数 | 类型 | 必填 | 描述 |
|---|---|---|---|
| success | Function | 是 | 接口调用成功的回调 |
| fail | Function | 否 | 接口调用失败的回调函数 |
| fail | Function | 否 | 接口调用结束的回调函数(调用成功、失败都会执行) |
success返回参数说明:
| 属性 | 说明 |
|---|---|
| model | 手机型号 |
| pixelRatio | 设备像素比 |
| windowWidth | 窗口宽度 |
| windowHeight | 窗口高度 |
| language | 微信设置的语言 |
| version | 微信版本号 |
| system | 操作系统版本 |
| platform | 客户端平台 |
wx.getSystemInfo({
success: function(res) {
console.log(res.model)
console.log(res.pixelRatio)
console.log(res.windowWidth)
console.log(res.windowHeight)
console.log(res.language)
console.log(res.version)
console.log(res.platform)
}
})
【wx.getSystemInfoSync()】:【获取系统信息同步接口。】
try {
var res = wx.getSystemInfoSync()
console.log(res.model)
console.log(res.pixelRatio)
console.log(res.windowWidth)
console.log(res.windowHeight)
console.log(res.language)
console.log(res.version)
console.log(res.platform)
} catch (e) {
// Do something when catch error
}
