小程序开发API之wx.canIUse(判断API是否可用的API)

版权声明:欢迎转载,可Chat交流,写博不易请标明出处: https://blog.csdn.net/JackJia2015/article/details/86524844

wx.canIUse

boolean wx.canIUse(string schema)
判断小程序的API,回调,参数,组件等是否在当前版本可用。

返回值:boolean 当前版本是否可用
参数:string schema 使用 ${API}.${method}.${param}.${options}或者 ${component}.${attribute}.${option} 方式来调用
参数说明:

  • ${API} 代表 API 名字
  • ${method} 代表调用方式,有效值为return, success, object, callback
  • ${param} 代表参数或者返回值
  • ${options} 代表参数的可选值
  • ${component} 代表组件名字
  • ${attribute} 代表组件属性
  • ${option} 代表组件属性的可选值

例如
index.js

onLoad: function (options) {

    console.log('蓝牙模块当前版本是否可用:',wx.canIUse('openBluetoothAdapter'))

    console.log('获取系统屏幕宽度当前版本是否可用:', wx.canIUse('getSystemInfo.success.screenWidth'))

    console.log('消息提示框自定义图标当前版本是否可用:', wx.canIUse('showToast.object.image'))
    
  },

打印结果:

蓝牙模块当前版本是否可用: true
获取系统屏幕宽度当前版本是否可用: true
消息提示框自定义图标当前版本是否可用: true





猜你喜欢

转载自blog.csdn.net/JackJia2015/article/details/86524844