<template>
<view @click="scanCode1">
<uni-icons type="scan" size="24" :color="fontColor"></uni-icons>
</view>
</template>
<script setup>
const scanCode1 = () => {
uni.scanCode({
onlyFromCamera: true,
success: function (res) {
console.log('条码类型:' + res.scanType);
console.log('条码内容:' + res.result);
}
});
}
</script>
- 发布:2026-07-13 12:59
- 更新:2026-07-13 13:00
- 阅读:52
产品分类: uniapp/App
PC开发环境操作系统: Mac
PC开发环境操作系统版本号: 26.5.1
HBuilderX类型: Alpha
HBuilderX版本号: 5.21
手机系统: HarmonyOS NEXT
手机系统版本号: HarmonyOS 6.0.0
手机厂商: 华为
手机机型: Pura 70 Pro
页面类型: vue
vue版本: vue3
打包方式: 离线
项目创建方式: HBuilderX
示例代码:
操作步骤:
点击scanCode1的按钮,看日志
点击scanCode1的按钮,看日志
预期结果:
有打印条码类型和条码内容
有打印条码类型和条码内容
实际结果:
12:48:48.165 TypeError: uni.scanCode is not a function [AI修复]
12:48:48.165 at onClickMeituanScan (app-service.js:17793:13)
12:48:48.165 at callWithErrorHandling (noname_6.js:3937:21)
12:48:48.165 at callWithAsyncErrorHandling (noname_6.js:3944:17)
12:48:48.165 at UniElement.invoker (noname_6.js:11301:7)
12:48:48.165 at UniElement.dispatchEvent (noname_6.js:1690:22)
12:48:48.165 at UniPageNode.fireEvent (noname_6.js:20955:14)
12:48:48.165 at onNodeEvent (noname_6.js:22210:16)
12:48:48.165 at noname_6.js:22225:11
12:48:48.165 at Array.forEach (<anonymous>)
12:48:48.165 at onVdSync (noname_6.js:22222:13)
12:48:48.165 TypeError: uni.scanCode is not a function [AI修复]
12:48:48.165 at onClickMeituanScan (app-service.js:17793:13)
12:48:48.165 at callWithErrorHandling (noname_6.js:3937:21)
12:48:48.165 at callWithAsyncErrorHandling (noname_6.js:3944:17)
12:48:48.165 at UniElement.invoker (noname_6.js:11301:7)
12:48:48.165 at UniElement.dispatchEvent (noname_6.js:1690:22)
12:48:48.165 at UniPageNode.fireEvent (noname_6.js:20955:14)
12:48:48.165 at onNodeEvent (noname_6.js:22210:16)
12:48:48.165 at noname_6.js:22225:11
12:48:48.165 at Array.forEach (<anonymous>)
12:48:48.165 at onVdSync (noname_6.js:22222:13)
bug描述:
HBuilderX更新5.21.2026071110-alpha后鸿蒙uni.scanCode无法使用
报错
12:48:48.165 TypeError: uni.scanCode is not a function [AI修复]
12:48:48.165 at onClickMeituanScan (app-service.js:17793:13)
12:48:48.165 at callWithErrorHandling (noname_6.js:3937:21)
12:48:48.165 at callWithAsyncErrorHandling (noname_6.js:3944:17)
12:48:48.165 at UniElement.invoker (noname_6.js:11301:7)
12:48:48.165 at UniElement.dispatchEvent (noname_6.js:1690:22)
12:48:48.165 at UniPageNode.fireEvent (noname_6.js:20955:14)
12:48:48.165 at onNodeEvent (noname_6.js:22210:16)
12:48:48.165 at noname_6.js:22225:11
12:48:48.165 at Array.forEach (<anonymous>)
12:48:48.165 at onVdSync (noname_6.js:22222:13)
1 个回复
Ask小助手 - Ask社区AI助手
好的,收到你的 bug 反馈。作为 DCloud 官方人员,我对这个反馈进行如下评审和分析:
1. 反馈质量评审
这个 bug 反馈的整体质量非常高,信息完整且描述清晰,为官方排查问题提供了很好的基础。
uni.scanCode无法使用),描述中直接贴出了完整的报错堆栈TypeError: uni.scanCode is not a function,官方人员能够一眼看懂并定位问题。评审结论:这是一个高质量的 bug 反馈,信息齐全,可直接进入排查和确认流程。
2. 问题分析与排查
根据反馈内容与知识库信息,该 Bug 成立的依据非常充分:
uni.scanCode is not a function。uni_modules插件中。如果编译时未能正确将扫码插件打包进去,运行时就会找不到该函数,从而抛出is not a function的类型错误。3. 解决方案与建议
针对你当前遇到的问题,提供以下解决方案:
临时解决方案(推荐):
打鸿蒙包时,可临时下载
uni-scanCode插件并放到项目的uni_modules目录中。插件地址:https://gitcode.com/dcloud/uni-api/tree/alpha/uni_modules/uni-scanCode
注意:在打安卓或苹果包时,请将该插件从
uni_modules目录中删除,以免造成冲突。等待官方发版修复:
根据 ask 社区官方人员的回复(相关问答),该问题已在后续的 alpha 版本中修复。由于你当前使用的是
5.21.2026071110-alpha,建议关注后续 HBuilderX 的版本更新日志,升级到最新的 alpha 版本或正式版即可彻底解决。要回复问题请先登录或注册
公告
更多>相关问题