当前位置:网站首页>华为快应用中如何实现同时传递事件对象和自定义参数
华为快应用中如何实现同时传递事件对象和自定义参数
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>
打印日志如下:
快应用事件绑定介绍:
边栏推荐
- Pywin32 opens the specified window
- stm32和電機開發(上比特系統)
- nodejs+express+mysql简单博客搭建
- The nanny level tutorial of flutter environment configuration makes the doctor green to the end
- MySQL keyword
- Convert yv12 to rgb565 image conversion, with YUV to RGB test
- Flutter环境配置保姆级教程,让doctor一绿到底
- The URL in the RTSP setup header of the axis device cannot take a parameter
- Oracle 笔记
- UWA报告使用小技巧,你get了吗?(第四弹)
猜你喜欢
快速做出原型
简洁、快速、节约内存的Excel处理工具EasyExcel
Jsp webshell Free from killing - The Foundation of JSP
MongoDB 学习整理(条件操作符,$type 操作符,limit()方法,skip() 方法 和 sort() 方法)
华为游戏初始化init失败,返回错误码907135000
Hdu1234 door opener and door closer (water question)
4.随机变量
12. Process synchronization and semaphore
STM32 and motor development (upper system)
2. Hacking lab script off [detailed writeup]
随机推荐
flume 190 INSTALL
12. Process synchronization and semaphore
nodejs+express+mysql简单博客搭建
The nanny level tutorial of flutter environment configuration makes the doctor green to the end
6种单例模式的实现方式
PCL 点云转深度图像
Mongodb quickly get started with some simple operations of mongodb command line
Hdu1234 door opener and door closer (water question)
Kustomize user manual
Considerations for Apache deploying static web page projects
From Read and save in bag file Jpg pictures and PCD point cloud
【付费推广】常见问题合集,推荐榜单FAQ
长投学堂上面的账户安全吗?
1287_ Implementation analysis of prvtaskistasksuspended() interface in FreeRTOS
What is the significance of the college entrance examination
14. Code implementation of semaphore
4. Random variables
传输优化抽象
华为联机对战服务玩家掉线重连案例总结
"Talking about podcasts" vol.352 the age of children: breaking the inner scroll, what can we do before high school?