当前位置:网站首页>华为快应用中如何实现同时传递事件对象和自定义参数
华为快应用中如何实现同时传递事件对象和自定义参数
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>打印日志如下:

快应用事件绑定介绍:
边栏推荐
- 长投学堂上面的账户安全吗?
- AttributeError: type object ‘Image‘ has no attribute ‘fromarray‘
- MySQL lethal serial question 4 -- are you familiar with MySQL logs?
- "Talking about podcasts" vol.352 the age of children: breaking the inner scroll, what can we do before high school?
- Leetcode+ 76 - 80 storm search topic
- UVM factory mechanism
- 面对不确定性,供应链的作用
- Importing tables from sqoop
- 首份中国企业敏捷实践白皮书发布| 附完整下载
- LabVIEW为什么浮点数会丢失精度
猜你喜欢

Retrofit's callback hell is really vulnerable in kotlin synergy mode!

从MediaRecord录像中读取H264参数

13. Semaphore critical zone protection

Introduction to MySQL 8 DBA foundation tutorial

How to get the password of cpolar?

AI技术产业热点分析

4.随机变量

Read H264 parameters from mediarecord recording

Dialogue Wu Gang: why do I believe in the rise of "big country brands"?

session-cookie与token
随机推荐
高考的意义是什么
AI技术产业热点分析
AttributeError: type object ‘Image‘ has no attribute ‘fromarray‘
Operator-1 first acquaintance with operator
PCL之K-d树与八叉树
flume 190 INSTALL
PCL之滤波
《实习报告》Skywalking分布式链路追踪?
2.hacking-lab脚本关[详细writeup]
传输优化抽象
MYSQL环境配置
Solutions to a series of problems in sqoop job creation
MySQL数据库远程访问权限设置
Transport Optimization abstraction
MongoDB-快速上手MongoDB命令行的一些简单操作
KS009基于SSH实现宠物管理系统
4.随机变量
互联网快讯:腾讯会议应用市场正式上线;Soul赴港递交上市申请书
Win11 arm系统配置.net core环境变量
Set the playback speed during the playback of UOB equipment