uni.scanCode({
scanType: ["barCode"], //条形码
onlyFromCamera: true, //为true只允许相机扫码,不加允许相册扫码
success: function(res) {
_this.code = res.result;
console.log(_this.code)
},
fail: function(err) {
uni.showToast({
title: '扫码失败'
})
}
})
- 发布:2022-10-20 09:56
- 更新:2023-11-10 16:44
- 阅读:442
产品分类: uniapp/小程序/微信
PC开发环境操作系统: Windows
PC开发环境操作系统版本号: 10
HBuilderX类型: 正式
HBuilderX版本号: 3.6.4
第三方开发者工具版本号: 1.06.2210141
基础库版本号: 2.26.2
项目创建方式: HBuilderX
示例代码:
操作步骤:
<template>
<view >
<view class="input-icon" @click="toscan">
<i class="iconfont icon-saomiao" />
</view>
</view>
</template>
<script>
export default {
components: {
},
computed: {
},
data() {
return {
code:'',//请输入商品条码或编码
},
async onShow() {
},
methods: {
uni.scanCode({
scanType: ["barCode"], //条形码
onlyFromCamera: true, //为true只允许相机扫码,不加允许相册扫码
success: function(res) {
_this.code = res.result;
console.log(_this.code)
},
fail: function(err) {
uni.showToast({
title: '扫码失败'
})
}
})
}
</script>
<template>
<view >
<view class="input-icon" @click="toscan">
<i class="iconfont icon-saomiao" />
</view>
</view>
</template>
<script>
export default {
components: {
},
computed: {
},
data() {
return {
code:'',//请输入商品条码或编码
},
async onShow() {
},
methods: {
uni.scanCode({
scanType: ["barCode"], //条形码
onlyFromCamera: true, //为true只允许相机扫码,不加允许相册扫码
success: function(res) {
_this.code = res.result;
console.log(_this.code)
},
fail: function(err) {
uni.showToast({
title: '扫码失败'
})
}
})
}
</script>
预期结果:
{
charSet: "UTF-8"
codeVersion: 0
errMsg: "scanCode:ok"
rawData: "Njk3MzUzNzM4Njc0Ng=="
result: "6973537386746"
scanType: "EAN_13"
proto: Object
}
{
charSet: "UTF-8"
codeVersion: 0
errMsg: "scanCode:ok"
rawData: "Njk3MzUzNzM4Njc0Ng=="
result: "6973537386746"
scanType: "EAN_13"
proto: Object
}
实际结果:
{
charSet: "UTF-8"
codeVersion: 0
errMsg: "scanCode:ok"
rawData: "MDAxMjE0MDg="
result: "00121408"
scanType: "UPC_E"
proto: Object
}
{
charSet: "UTF-8"
codeVersion: 0
errMsg: "scanCode:ok"
rawData: "MDAxMjE0MDg="
result: "00121408"
scanType: "UPC_E"
proto: Object
}
1***@qq.com (作者)
这个目前不是uniapp 里面 调接口出现的问题吗? 扫码返回的数据类型不同啊
2022-10-20 11:28
1***@qq.com (作者)
微信原生的扫一扫 或者第三方的扫一扫就不会出现这样的问题
2022-10-20 11:30
BoredApe
回复 1***@qq.com: 码给一个。使用小程序原生的scanCode扫码返回的只正常的吗?
2022-10-20 13:56