小程序 工具api(用户环境变量、判断api等可用性、buffer转换)

1、获取环境变量
	wx.env		返回文件系统中的用户目录路径(本地路径)

2、判断小程序的API、回调、参数、组件等是否在当前版本可用
	wx.canIUse('API.method.param.option'|'component.attribute.option')
		${API} 	  代表 API 名字
		${method} 代表调用方式,有效值为return, success, object, callback
		${param}  代表参数或者返回值
		${option} 代表参数的可选值或者返回值的属性
		${component} 代表组件名字
		${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')

3、base64合ArrayBuffer相互转换
	 wx.base64ToArrayBuffer(base64)
	 wx.arrayBufferToBase64(arrayBuffer)
	 	const arrayBuffer = new Uint8Array([11, 22, 33])

猜你喜欢

转载自blog.csdn.net/weixin_43294560/article/details/121532804
今日推荐