当前位置:网站首页>华为快应用中如何实现同时传递事件对象和自定义参数
华为快应用中如何实现同时传递事件对象和自定义参数
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>
打印日志如下:
快应用事件绑定介绍:
边栏推荐
猜你喜欢
Jsp webshell Free from killing - The Foundation of JSP
Win11 arm系统配置.net core环境变量
"Talking about podcasts" vol.352 the age of children: breaking the inner scroll, what can we do before high school?
JSP webshell免杀——JSP的基础
Database dictionary Navicat automatic generation version
How to get the password of cpolar?
13. Semaphore critical zone protection
互联网快讯:腾讯会议应用市场正式上线;Soul赴港递交上市申请书
Beautiful and intelligent, Haval H6 supreme+ makes Yuanxiao travel safer
使用华为性能管理服务,按需配置采样率
随机推荐
【AGC】构建服务3-认证服务示例
P1055 [noip2008 popularization group] ISBN number
【TS】1368- 秒懂 TypeScript 泛型工具类型!
Leetcode+ 76 - 80 storm search topic
UWA report uses tips. Did you get it? (the fourth bullet)
Start class, data analysis, high salary training plan, elite class
使用sqlcipher打开加密的sqlite方法
《实习报告》Skywalking分布式链路追踪?
Easyexcel, a concise, fast and memory saving excel processing tool
Retrofit's callback hell is really vulnerable in kotlin synergy mode!
SPSS做Shapiro-Wilk正态分析
02-taildir source
大华设备播放过程中设置播放速度
js promise.all
Pywin32打开指定窗口
Is this code PHP MySQL redundant?
Use WinDbg to statically analyze dump files (summary of practical experience)
Redis set password
Shell programming 01_ Shell foundation
MySQL lethal serial question 3 -- are you familiar with MySQL locks?