HanFengA7
HanFengA7
  • 发布:2026-02-04 11:22
  • 更新:2026-02-04 11:23
  • 阅读:24

【报Bug】新版HbuliderX5.0.2026013113-alpha 鸿蒙上uni.scanCode无法调起

分类:鸿蒙Next

产品分类: uniapp/App

PC开发环境操作系统: Mac

PC开发环境操作系统版本号: 26.2

HBuilderX类型: Alpha

HBuilderX版本号: 5.0

手机系统: HarmonyOS NEXT

手机系统版本号: HarmonyOS 6.0.0

手机厂商: 华为

手机机型: Pura 70 Pro

页面类型: vue

vue版本: vue3

打包方式: 离线

项目创建方式: HBuilderX

示例代码:
<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>

操作步骤:

点击scanCode1的按钮,看原生日志

预期结果:

有打印条码类型和条码内容

实际结果:

报错```javascript
11:17:13.189 TypeError: uni.scanCode is not a function
11:17:13.189 at scanCode1 (app-service.js:9350:13)
11:17:13.189 at callWithErrorHandling (noname_6.js:3821:21)
11:17:13.189 at callWithAsyncErrorHandling (noname_6.js:3828:17)
11:17:13.189 at UniElement.invoker (noname_6.js:9776:7)
11:17:13.189 at UniElement.dispatchEvent (noname_6.js:1681:22)
11:17:13.189 at UniPageNode.fireEvent (noname_6.js:19393:14)
11:17:13.189 at onNodeEvent (noname_6.js:20614:16)
11:17:13.189 at noname_6.js:20629:11
11:17:13.189 at Array.forEach (<anonymous>)
11:17:13.189 at onVdSync (noname_6.js:20626:13)

bug描述:

报错日志

11:17:13.189 TypeError: uni.scanCode is not a function  
11:17:13.189     at scanCode1 (app-service.js:9350:13)  
11:17:13.189     at callWithErrorHandling (noname_6.js:3821:21)  
11:17:13.189     at callWithAsyncErrorHandling (noname_6.js:3828:17)  
11:17:13.189     at UniElement.invoker (noname_6.js:9776:7)  
11:17:13.189     at UniElement.dispatchEvent (noname_6.js:1681:22)  
11:17:13.189     at UniPageNode.fireEvent (noname_6.js:19393:14)  
11:17:13.189     at onNodeEvent (noname_6.js:20614:16)  
11:17:13.189     at noname_6.js:20629:11  
11:17:13.189     at Array.forEach (<anonymous>)  
11:17:13.189     at onVdSync (noname_6.js:20626:13)
2026-02-04 11:22 负责人:无 分享
已邀请:
Ask小助手

Ask小助手 - Ask社区AI助手

需补充具体的示例代码和HBuilderX版本信息。
欢迎到专业群( uni-app鸿蒙化技术交流群 ) 咨询,群中有相关专业的管理员和群友。

作为 DCloud 官方评审人员,对该条 bug 反馈的评审结论如下:

  1. 反馈完整性
    • 标题、描述、代码示例、复现步骤、预期/实际结果、以及 PC/手机环境、HBuilderX 版本、Vue 版本、设备型号等分类信息均已提供,内容完整。
    • 代码示例可直接复制运行,无需额外调整。
    • 复现步骤清晰:点击按钮即可触发,官方人员可据此复现。

  2. bug 是否成立
    根据知识库 barcode > uni.scanCode(OBJECT) > scanCode 兼容性-2 的说明:

    HarmonyOS Next 不支持 Barcode 组件,但并未列出 uni.scanCode API 在 HarmonyOS Next 的兼容性。
    同时,在“结构化文档知识库”中明确标注:
    HarmonyOS Next 不支持 Barcode(组件),但 uni.scanCode API 的兼容性表格未列出 HarmonyOS Next。
    结合当前报错信息 “TypeError: uni.scanCode is not a function”,可判定:
    • 在 HarmonyOS Next 平台,uni.scanCode 尚未实现或尚未随 Alpha 版 HBuilderX 5.0 提供,因此该 bug 成立。

  3. 建议与后续处理
    • 已向用户说明:当前 HarmonyOS Next 暂未支持 uni.scanCode,请等待后续版本更新。
    • 如急需扫码功能,可引导用户到插件市场搜索“扫码”关键词,使用社区提供的 uts 扫码插件作为临时替代:https://ext.dcloud.net.cn/search?q=%E6%89%AB%E7%A0%81&orderBy=Relevance&cat1=8&cat2=81
    • 建议用户在后续 HBuilderX 更新日志中关注 “HarmonyOS Next 新增 uni.scanCode 支持” 的说明。

内容为 AI 生成,仅供参考

要回复问题请先登录注册