2***@qq.com
2***@qq.com
  • 发布:2026-04-01 13:43
  • 更新:2026-04-01 13:43
  • 阅读:61

【报Bug】蒸汽模式dispatchEvent无法传导事件参数

分类:鸿蒙Next

产品分类: uniapp/App

PC开发环境操作系统: Mac

PC开发环境操作系统版本号: 26.1(25B78)

HBuilderX类型: 正式

HBuilderX版本号: 5.06

手机系统: HarmonyOS NEXT

手机系统版本号: HarmonyOS 6.0.0

手机厂商: 华为

手机机型: 华为Nova14pro

页面类型: vue

vue版本: vue3

打包方式: 云端

项目创建方式: HBuilderX

示例代码:

    private name : string | null = null  
    private $element : UniNativeViewElement;  
    private builder : BuilderNode<[NativeAmapOptions]> | null = null  
    // 初始化 buildButton 默认参数  
    private params : NativeAmapOptions = {  
        id: '',  
        // appKey: '',  
        showLocation: false,  
        owerIcon: '',  
        // name: '',  
        onReady: () => {  
            this.$element.dispatchEvent(new UniNativeViewEvent("isready", {}))  
        },  
        onMapClick: (point) => {  
            this.$element.dispatchEvent(new UniNativeViewEvent("mapclick", JSON.parseObject(JSON.stringify(point))!))  
        },  
        onCameraChange: (position) => {  
            this.$element.dispatchEvent(new UniNativeViewEvent("camerachange", JSON.parseObject(JSON.stringify(position))!))  
        },  
        onCameraChangeFinish: (position) => {  
            this.$element.dispatchEvent(new UniNativeViewEvent("camerafinish", JSON.parseObject(JSON.stringify(position))!))  
        },  
        onMarkerClick: (markerId) => {  
            let result = {  
                markerId: markerId  
            }  
            this.$element.dispatchEvent(new UniNativeViewEvent("markertap", JSON.parseObject(JSON.stringify(result))!))  
        }  
        // onClick: () => {  
        //  this.$element.dispatchEvent(new UniNativeViewEvent("customClick", {}))  
        // }  
    }  
    constructor(element : UniNativeViewElement) {  
        // 绑定 wrapBuilder 函数  
        this.builder = element.bindHarmonyWrappedBuilder(wrapBuilder<[NativeAmapOptions]>(buildAmap), this.params)  
        this.$element = element  
        // 绑定当前实例为自定义的controller,方便其他地方通过 element 获取使用  
        this.$element.bindHarmonyController(this)  
    }  
}```  

操作步骤:

在按照文档编写标准模式组件,在调用this.$element.dispatchEvent(new UniNativeViewEvent("mapclick", JSON.parseObject(JSON.stringify(point))!))中JSON.parseObject(JSON.stringify(point))!)是非空的

预期结果:

在自己的页面外部调用@mapclick时候可以像非蒸汽模式下正常收到数据

实际结果:

在自己的页面调用该标准模式组件中的@mapclick事件,能够正常触发,但收不到内容

bug描述:

在蒸汽模式下标准模式组件this.$element.dispatchEvent(new UniNativeViewEvent("camerafinish", JSON.parseObject(JSON.stringify(position))!))将参数传导出去,在自己的页面通过@camerafinish接收事件,可以触发事件但收不到传来的数据

2026-04-01 13:43 负责人:无 分享
已邀请:

要回复问题请先登录注册