uni-app 二维码扫描识别功能
由此可以看出,uni-app自帶api在h5平臺時是不能調用uni.scanCode的,那么非h5平臺實現二維碼掃描識別方法:
uni.scanCode({
?? ??? ??? ??? ??? ??? ??? ??? ??? ?success(res) {
?? ??? ??? ??? ??? ??? ??? ??? ??? ??? ?_this.tempImgUrl = res.path
?? ??? ??? ??? ??? ??? ??? ??? ??? ??? ?_this.isChooseImg = true
?? ??? ??? ??? ??? ??? ??? ??? ??? ??? ?_this.resultStr = res.result
?? ??? ??? ??? ??? ??? ??? ??? ??? ??? ?console.log("其他平臺 二維碼解析結果 resultStr = " + _this.resultStr)
?? ??? ??? ??? ??? ??? ??? ??? ??? ?}
?? ??? ??? ??? ??? ??? ??? ??? ?})
H5:
首先添加reqrcode.js,可以在百度搜索下載比較多
在script中引用
let reqrcode = require("../../components/scancode/reqrcode.js")
?方法:選擇二維碼圖片再解析
uni.chooseImage({
?? ??? ??? ??? ??? ??? ?count: 1, //默認9
?? ??? ??? ??? ??? ??? ?sizeType: ['original', 'compressed'], //可以指定是原圖還是壓縮圖,默認二者都有
?? ??? ??? ??? ??? ??? ?sourceType: ['album', "camera"], //從相冊選擇 、使用相機
?? ??? ??? ??? ??? ??? ?success(res) {
?? ??? ??? ??? ??? ??? ??? ?_this.tempImgUrl = res.tempFilePaths[0]
?? ??? ??? ??? ??? ??? ??? ?_this.isChooseImg = true
?? ??? ??? ??? ??? ??? ??? ?console.log("再次選擇確認單 tempImgUrl = " + _this.tempImgUrl)
?? ??? ??? ??? ??? ??? ??? ?reqrcode.qrcode.decode(res.tempFilePaths[0])
?? ??? ??? ??? ??? ??? ??? ?reqrcode.qrcode.callback = function(res1) {
?? ??? ??? ??? ??? ??? ??? ??? ?_this.resultStr = res1
?? ??? ??? ??? ??? ??? ??? ??? ?console.log("H5 二維碼解析結果 resultStr = " + _this.resultStr)
?? ??? ??? ??? ??? ??? ??? ?}
?? ??? ??? ??? ??? ??? ?}
?? ??? ??? ??? ??? ?})
?
總結
以上是生活随笔為你收集整理的uni-app 二维码扫描识别功能的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: android TV端如何读取微信网页版
- 下一篇: 微信pc内嵌二维码的自定义样式更改