const scanQRCode = () => {
uni.scanCode({
success: (res: ScanCodeSuccess) => {
console.log('res: ',res);
},
fail: (err: ScanCodeFail) => {
console.log('err: ',err);
// 需要注意的是小程序扫码不需要申请相机权限
}
});
}

- 发布:2025-06-22 15:55
- 更新:2025-06-23 11:17
- 阅读:32
产品分类: uni-app x/App
PC开发环境操作系统: Windows
PC开发环境操作系统版本号: win10
HBuilderX类型: 正式
HBuilderX版本号: 4.66
手机系统: Android
手机系统版本号: Android 11
手机厂商: 小米
手机机型: 11pro
页面类型: vue
vue版本: vue3
打包方式: 离线
项目创建方式: HBuilderX
示例代码:
操作步骤:
保存文件时进行编译到安卓代码报错
保存文件时进行编译到安卓代码报错
预期结果:
应编译正常
应编译正常
实际结果:
编译时报错:```javascript
5:46:39.939 error: Unresolved reference: uni_scanCode
15:46:39.939 at pages/index/index.uvue:72:2
15:46:39.939 70 |
15:46:39.939 71 | const scanQRCode = () => {
15:46:39.939 72 | uni.scanCode({
15:46:39.939 | ^
15:46:39.939 73 | success: (res: ScanCodeSuccess) => {
15:46:39.939 74 | console.log('res: ',res);
15:46:39.939 error: Unresolved reference: ScanCodeOptions
15:46:39.939 at pages/index/index.uvue:72:2
15:46:39.939 70 |
15:46:39.939 71 | const scanQRCode = () => {
15:46:39.939 72 | uni.scanCode({
15:46:39.939 | ^
15:46:39.939 73 | success: (res: ScanCodeSuccess) => {
15:46:39.939 74 | console.log('res: ',res);
15:46:39.939 error: Unresolved reference: ScanCodeSuccess
15:46:39.940 at pages/index/index.uvue:73:22
15:46:39.940 71 | const scanQRCode = () => {
15:46:39.940 72 | uni.scanCode({
15:46:39.940 73 | success: (res: ScanCodeSuccess) => {
15:46:39.940 | ^
15:46:39.940 74 | console.log('res: ',res);
15:46:39.940 75 |
15:46:39.940 error: Unresolved reference: ScanCodeFail
15:46:39.940 at pages/index/index.uvue:77:19
15:46:39.940 75 |
15:46:39.940 76 | },
15:46:39.940 77 | fail: (err: ScanCodeFail) => {
15:46:39.940 | ^
15:46:39.940 78 | console.log('err: ',err);
15:46:39.940 79 | // 需要注意的是小程序扫码不需要申请相机权限
15:49:30.923 App Hide at App.uvue:11
编译时报错:```javascript
5:46:39.939 error: Unresolved reference: uni_scanCode
15:46:39.939 at pages/index/index.uvue:72:2
15:46:39.939 70 |
15:46:39.939 71 | const scanQRCode = () => {
15:46:39.939 72 | uni.scanCode({
15:46:39.939 | ^
15:46:39.939 73 | success: (res: ScanCodeSuccess) => {
15:46:39.939 74 | console.log('res: ',res);
15:46:39.939 error: Unresolved reference: ScanCodeOptions
15:46:39.939 at pages/index/index.uvue:72:2
15:46:39.939 70 |
15:46:39.939 71 | const scanQRCode = () => {
15:46:39.939 72 | uni.scanCode({
15:46:39.939 | ^
15:46:39.939 73 | success: (res: ScanCodeSuccess) => {
15:46:39.939 74 | console.log('res: ',res);
15:46:39.939 error: Unresolved reference: ScanCodeSuccess
15:46:39.940 at pages/index/index.uvue:73:22
15:46:39.940 71 | const scanQRCode = () => {
15:46:39.940 72 | uni.scanCode({
15:46:39.940 73 | success: (res: ScanCodeSuccess) => {
15:46:39.940 | ^
15:46:39.940 74 | console.log('res: ',res);
15:46:39.940 75 |
15:46:39.940 error: Unresolved reference: ScanCodeFail
15:46:39.940 at pages/index/index.uvue:77:19
15:46:39.940 75 |
15:46:39.940 76 | },
15:46:39.940 77 | fail: (err: ScanCodeFail) => {
15:46:39.940 | ^
15:46:39.940 78 | console.log('err: ',err);
15:46:39.940 79 | // 需要注意的是小程序扫码不需要申请相机权限
15:49:30.923 App Hide at App.uvue:11
bug描述:
二维码扫码,hbuilder安卓编译时报错,15:46:39.939 [plugin:uni:app-uts] 编译失败
15:46:39.939 error: Unresolved reference: scanCode
1 个回复
DCloud_UNI_yuhe
安卓上 4.71 支持,看你这 66 应该还不支持