Skip to main content
Version: 2.x

Taro.canIUse(schema)

判断小程序的 API,回调,参数,组件等是否在当前版本可用。

参考文档

类型

(schema: string) => boolean

参数

使用 ${API}.${method}.${param}.${option} 或者 ${component}.${attribute}.${option} 方式来调用

参数说明

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

示例代码

Taro.canIUse('openBluetoothAdapter')
Taro.canIUse('getSystemInfoSync.return.screenWidth')
Taro.canIUse('getSystemInfo.success.screenWidth')
Taro.canIUse('showToast.object.image')
Taro.canIUse('onCompassChange.callback.direction')
Taro.canIUse('request.object.method.GET')
Taro.canIUse('live-player')
Taro.canIUse('text.selectable')
Taro.canIUse('button.open-type.contact')

API 支持度

API微信小程序H5React Native
Taro.canIUse✔️