小程序wx.canIUse使用
boolean wx.canIUse(string schema)
判斷小程序的API,回調,參數,組件等是否在當前版本可用。
參數
string schema
使用 ${API}.${method}.${param}.${option} 或者 <code>${component}.${attribute}.${option} 方式來調用
返回值
boolean
當前版本是否可用
參數說明
${API} 代表 API 名字</li><li><code>${method} 代表調用方式,有效值為return, success, object, callback
${param} 代表參數或者返回值</li><li><code>${option} 代表參數的可選值或者返回值的屬性
${component} 代表組件名字</li><li><code>${attribute} 代表組件屬性
${option} 代表組件屬性的可選值
示例代碼
// 對象的屬性或方法
wx.canIUse('console.log')
wx.canIUse('CameraContext.onCameraFrame')
wx.canIUse('CameraFrameListener.start')
wx.canIUse('Image.src')
// wx接口參數、回調或者返回值
wx.canIUse('openBluetoothAdapter')
wx.canIUse('getSystemInfoSync.return.safeArea.left')
wx.canIUse('getSystemInfo.success.screenWidth')
wx.canIUse('showToast.object.image')
wx.canIUse('onCompassChange.callback.direction')
wx.canIUse('request.object.method.GET')
// 組件的屬性
wx.canIUse('live-player')
wx.canIUse('text.selectable')
wx.canIUse('button.open-type.contact')
計算機學習推薦