当前位置:网站首页>How to transfer event objects and user-defined parameters simultaneously in Huawei express applications
How to transfer event objects and user-defined parameters simultaneously in Huawei express applications
2022-07-02 11:00:00 【Huawei Developer Forum】
Phenomenon description
The following methods are used in fast application js Event method of binding component , If you pass the event object and custom parameters at the same time, you will find that the parameters are not received correctly in the callback method , As shown below :
Problem code :
<template>
<!-- Only one root node is allowed in template. -->
<div class="container">
<input id="input1" type="button" value=" Jump " onclick="jump(event,1)"/>
</div>
</template>
<script>
module.exports = {
jump: function (event, v) {
console.info("e = " + JSON.stringify(event));
console.info("v = " + v);
}
}
</script>
Print the log as follows :
Problem analysis
The supported writing of event callback ( among { {}} It can be omitted ):
- "fn":fn Call back the function name for the event ( stay <script> There is a corresponding function implementation in ).
- "fn(a,b)": Function parameters, such as a,b It can be a constant , Or in <script> Of data Variables defined in ( Don't write in front this.).
- "a+b": expression , among a,b The data type is the same as above .
When the callback function is called , An... Will be automatically added at the end of the parameter list evt Parameters , adopt evt Parameter to access context data related to callback events ( Please refer to the component callback event description for the data content ), For example, click location of click event x,y.
Solution
Modify the code as follows :
<template>
<!-- Only one root node is allowed in template. -->
<div class="container">
<input id="input1" type="button" value=" Jump " onclick="jump(1)" />
</div>
</template>
<script>
module.exports = {
jump: function (v, evt) {
console.info("e = " + JSON.stringify(evt));
console.info("v = " + v);
}
}
</script>
Print the log as follows :
Introduction to fast application event binding :
边栏推荐
- AppGallery Connect场景化开发实战—图片存储分享
- UVM learning - object attribute of UVM phase
- UVM - configuration mechanism
- 二叉树专题--【深基16.例7】普通二叉树(简化版)(multiset 求前驱 后继 哨兵法)
- VSCode工具使用
- Shapiro Wilk normal analysis by SPSS
- Nodejs+express+mysql simple blog building
- 12. Process synchronization and semaphore
- Shell programming 01_ Shell foundation
- Win11 arm系统配置.net core环境变量
猜你喜欢
随机推荐
4. Random variables
13. Semaphore critical zone protection
PCL之滤波
MongoDB 学习整理(条件操作符,$type 操作符,limit()方法,skip() 方法 和 sort() 方法)
axis设备的rtsp setup头中的url不能带参
LeetCode+ 76 - 80 暴搜专题
长投学堂上面的账户安全吗?
学习open62541 --- [66] UA_String的生成方法
【TS】1368- 秒懂 TypeScript 泛型工具类型!
最详细MySql安装教程
QT学习日记8——资源文件添加
Internet News: Tencent conference application market was officially launched; Soul went to Hong Kong to submit the listing application
Set the playback speed during the playback of UOB equipment
Nodejs+express+mysql simple blog building
Shell programming 01_ Shell foundation
洛谷 P3398 仓鼠找 sugar(树上倍增 lca 判断树中两条路径是否相交 结论)
Mysql database remote access permission settings
1287_FreeRTOS中prvTaskIsTaskSuspended()接口实现分析
转换YV12到RGB565图像转换,附YUV转RGB测试
Open the encrypted SQLite method with sqlcipher