初次调用微信小程序的扫码,记录一下。其实也很简单直接调用微信官方提供的api就能实现
wx.scanCode()
// 允许从相机和相册扫码
wx.scanCode({
success (res) {
console.log(res)
}
})
// 只允许从相机扫码
wx.scanCode({
onlyFromCamera: true,
success (res) {
console.log(res)
}
})
下面是打印的log数据
里面的参数官方也有给解释
属性 | 类型 | 说明 |
---|---|---|
result | string | 所扫码的内容 |
scantype | string | 所扫码的类型 |
charSet | string | 所扫码的字符集 |
path | string | 当所扫的码为当前小程序二维码时,会返回此字段,内容为二维码携带的 path |
rawData | string | 原始数据,base64编码 |
代码实现
在这里插入代码片