微信小程序版本更新迭代很频繁,可能会出现某些接口不兼容的问题
这时可以使用wx.canIUse判断微信小程序的接口、组件等是否在当前版本可用
使用方法如下:
➢${API}.${method}.${param}.${options}➢ ${component}.${attribute}.${option}
它会返回一个布尔值,表示是否可用,如示例4-1所示
Page({onLoad: function (options) {var r1 = wx.canIUse('openBluetoothAdapter');var r2 = wx.canIUse('getSystemInfoSync.return.screenWidth');var r3 = wx.canIUse('getSystemInfo.success.screenWidth');console.log("can I use openBluetoothAdapter:",r1);console.log("can I use getSystemInfoSync:",r2);console.log("can I use getSystemInfo:",r3);}})

