当前位置:网站首页>华为快应用中如何实现同时传递事件对象和自定义参数
华为快应用中如何实现同时传递事件对象和自定义参数
2022-07-02 07:16:00 【华为开发者论坛】
现象描述
在快应用中采用如下js方式绑定组件的事件方法,同时传递事件对象和自定义参数会发现回调方法中没有正确接收到参数,如下所示:
问题代码:
<template>
<!-- Only one root node is allowed in template. -->
<div class="container">
<input id="input1" type="button" value="跳转" onclick="jump(event,1)"/>
</div>
</template>
<script>
module.exports = {
jump: function (event, v) {
console.info("e = " + JSON.stringify(event));
console.info("v = " + v);
}
}
</script>打印日志如下:

问题分析
事件回调支持的写法(其中{ {}}可以省略):
- "fn":fn为事件回调函数名(在<script>中有对应的函数实现)。
- "fn(a,b)":函数参数例如a,b可以是常量,或者是在<script>的data中定义的变量(前面不用写this.)。
- "a+b":表达式,其中a,b数据类型与上面相同。
回调函数被调用时,会在参数列表末尾自动添加一个evt参数,通过evt参数访问回调事件相关上下文数据(数据内容具体参看组件回调事件说明),例如点击事件的点击位置x,y。
解决方案
修改代码如下:
<template>
<!-- Only one root node is allowed in template. -->
<div class="container">
<input id="input1" type="button" value="跳转" onclick="jump(1)" />
</div>
</template>
<script>
module.exports = {
jump: function (v, evt) {
console.info("e = " + JSON.stringify(evt));
console.info("v = " + v);
}
}
</script>打印日志如下:

快应用事件绑定介绍:
边栏推荐
- PCL之K-d树与八叉树
- AttributeError: type object ‘Image‘ has no attribute ‘fromarray‘
- 【TS】1368- 秒懂 TypeScript 泛型工具类型!
- 14.信号量的代码实现
- UWA报告使用小技巧,你get了吗?(第四弹)
- 618 what is the secret of dominating the list again? Nike's latest financial report gives the answer
- UVM - configuration mechanism
- SUS系统可用性量表
- session-cookie与token
- Kustomize user manual
猜你喜欢

Flutter——Canvas自定义曲线图

4. Random variables

Ks009 implement pet management system based on SSH

Use WinDbg to statically analyze dump files (summary of practical experience)

Redis set password

从MediaRecord录像中读取H264参数

Mysql database remote access permission settings

SUS系统可用性量表

Disassembling Meitu SaaS: driving the plane to change the engine
![[Fantasy 4] introduction and use of UMG components (under update...)](/img/33/7e3b74192b7fd73d5145f85e061d1f.png)
[Fantasy 4] introduction and use of UMG components (under update...)
随机推荐
记录 AttributeError: ‘NoneType‘ object has no attribute ‘nextcall‘
(五)APA场景搭建之挡位控制设置
14. Code implementation of semaphore
软件产品管理系统有哪些?12个最佳产品管理工具盘点
AttributeError: type object ‘Image‘ has no attribute ‘fromarray‘
"Matching" is true love, a new attitude for young people to make friends
js promise. all
【AGC】如何解决事件分析数据本地和AGC面板中显示不一致的问题?
Pywin32打开指定窗口
【快应用】Win7系统使用华为IDE无法运行和调试项目
学习open62541 --- [66] UA_String的生成方法
MySQL lethal serial question 4 -- are you familiar with MySQL logs?
大华设备播放过程中设置播放速度
Thanos Receiver
Kustomize user manual
MySQL keyword
数据库字典Navicat自动生成版本
Easyexcel, a concise, fast and memory saving excel processing tool
Sus system availability scale
Excuse me, is it cost-effective to insure love life patron saint 2.0 increased lifelong life insurance? What are the advantages of this product?