微信小程序API系統信息,wx.getSystemInfo獲取系統信息
2020-09-27
導讀:wx.getSystemInfo(OBJECT) 獲取系統信息。 OBJECT參數說明: 參數 類型 必填 說明 success Function 是 接口調用成功的回調 fail Function 否 接口調用失敗的回調函數 complete Function 否 接口調用結束的回...
wx.getSystemInfo(OBJECT)
獲取系統信息。
OBJECT參數說明:
參數 | 類型 | 必填 | 說明 |
---|---|---|---|
success | Function | 是 | 接口調用成功的回調 |
fail | Function | 否 | 接口調用失敗的回調函數 |
complete | Function | 否 | 接口調用結束的回調函數(調用成功、失敗都會執行) |
success回調參數說明:
參數 | 說明 | 最低版本 |
---|---|---|
model | 手機型號 | |
pixelRatio | 設備像素比 | |
screenWidth | 屏幕寬度 | 1.1.0 |
screenHeight | 屏幕高度 | 1.1.0 |
windowWidth | 可使用窗口寬度 | |
windowHeight | 可使用窗口高度 | |
language | 微信設置的語言 | |
version | 微信版本號 | |
system | 操作系統版本 | |
platform | 客戶端平臺 | |
fontSizeSetting | 用戶字體大小設置。以“我-設置-通用-字體大小”中的設置為準,單位:px | 1.5.0 |
SDKVersion | 客戶端基礎庫版本 | 1.1.0 |
示例代碼:
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()
獲取系統信息同步接口
同步返回參數說明:
參數 | 說明 | 最低版本 |
---|---|---|
model | 手機型號 | |
pixelRatio | 設備像素比 | |
screenWidth | 屏幕寬度 | 1.1.0 |
screenHeight | 屏幕高度 | 1.1.0 |
windowWidth | 可使用窗口寬度 | |
windowHeight | 可使用窗口高度 | |
language | 微信設置的語言 | |
version | 微信版本號 | |
system | 操作系統版本 | |
platform | 客戶端平臺 | |
SDKVersion | 客戶端基礎庫版本 | 1.1.0 |
示例代碼:
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
}
wx.canIUse(String)
判斷小程序的API,回調,參數,組件等是否在當前版本可用。
String參數說明: 使用${API}.${method}.${param}.${options}
或者${component}.${attribute}.${option}
方式來調用,例如:
-
${API}
代表 API 名字 -
${method}
代表調用方式,有效值為return
,success
,object
,callback
-
${param}
代表參數或者返回值 -
${options}
代表參數的可選值 -
${component}
代表組件名字 -
${attribute}
代表組件屬性 -
${option}
代表組件屬性的可選值
例子:
wx.canIUse('openBluetoothAdapter')wx.canIUse('getSystemInfoSync.return.screenWidth')
wx.canIUse('getSystemInfo.success.screenWidth')
wx.canIUse('showToast.object.image')
wx.canIUse('onCompassChange.callback.direction')
wx.canIUse('request.object.method.GET')
wx.canIUse('contact-button')
wx.canIUse('text.selectable')
wx.canIUse('button.open-type.contact')
更多微信小程序開發教程,可以關注hi小程序。
第二部分:如何開通一個小商店
您可能感興趣: