<template>
<view>
<button @click="onScan">扫描</button>
</view>
</template>
<script>
export default {
data() {
return {
title: 'Hello'
}
},
methods: {
onScan(){
console.log('开始扫描');
var that = this;
uni.scanCode({
scanType: ['qrCode'],
success(res)
{
console.log('识别成功:', res);
},
fail(err)
{
console.log('识别失败:', res);
}
});
}
}
}
</script>
- 发布:2023-01-28 11:02
- 更新:2024-04-28 11:43
- 阅读:550
产品分类: uniapp/App
PC开发环境操作系统: Windows
PC开发环境操作系统版本号: win11专业版10.0.22000
HBuilderX类型: 正式
HBuilderX版本号: 3.6.18
手机系统: Android
手机系统版本号: Android 12
手机厂商: 小米
手机机型: 小米10pro
页面类型: vue
vue版本: vue2
打包方式: 云端
项目创建方式: HBuilderX
示例代码:
操作步骤:
<template>
<view>
<button @click="onScan">扫描</button>
</view>
</template>
<script>
export default {
data() {
return {
title: 'Hello'
}
},
methods: {
onScan(){
console.log('开始扫描');
var that = this;
uni.scanCode({
scanType: ['qrCode'],
success(res)
{
console.log('识别成功:', res);
},
fail(err)
{
console.log('识别失败:', res);
}
});
}
}
}
</script>
<template>
<view>
<button @click="onScan">扫描</button>
</view>
</template>
<script>
export default {
data() {
return {
title: 'Hello'
}
},
methods: {
onScan(){
console.log('开始扫描');
var that = this;
uni.scanCode({
scanType: ['qrCode'],
success(res)
{
console.log('识别成功:', res);
},
fail(err)
{
console.log('识别失败:', res);
}
});
}
}
}
</script>
预期结果:
都能识别成功
都能识别成功
实际结果:
直接扫码识别成功,从相册选择直接提示识别失败,并且没有走fail
回调
10:57:34.611 开始扫描 at pages/index/index.vue:16
10:57:38.008 App Hide at App.vue:10
10:57:40.363 App Show at App.vue:7
// 这里选择相册,直接有个吐司提示识别失败,没有打印信息
10:57:53.397 App Hide at App.vue:10
10:57:58.884 App Show at App.vue:7
10:58:05.168 识别成功:, [Object] {"scanType":"QR_CODE","path":"","charSet":"ISO8859_1","result":"4dc2f463498bd6d18c4f96f084a...} at pages/index/index.vue:22
直接扫码识别成功,从相册选择直接提示识别失败,并且没有走fail
回调
10:57:34.611 开始扫描 at pages/index/index.vue:16
10:57:38.008 App Hide at App.vue:10
10:57:40.363 App Show at App.vue:7
// 这里选择相册,直接有个吐司提示识别失败,没有打印信息
10:57:53.397 App Hide at App.vue:10
10:57:58.884 App Show at App.vue:7
10:58:05.168 识别成功:, [Object] {"scanType":"QR_CODE","path":"","charSet":"ISO8859_1","result":"4dc2f463498bd6d18c4f96f084a...} at pages/index/index.vue:22
bug描述:
【报Bug】uni.scanCode['qrCode']直接扫码可以识别,从相册中选择就提示识别失败
m***@qq.com (作者)
用别的二维码有的可以识别正常
2023-01-29 13:57