当前位置:网站首页>微信小程序通过点击事件传参(data-)
微信小程序通过点击事件传参(data-)
2022-06-30 22:15:00 【水星记_】
前言
大家都知道在 vue 中,我们可以直接在点击事件中放入传递的参数进行传参;然而微信小程序中并不适用这样的写法,但是微信小程序可以通过自定义属性从而绑定参数使用。
data- 的用法
微信小程序可以通过直接写 data-index="1" 进行数据的绑定 ,利用 bindtap 点击事件执行函数从而获取到参数信息。
<view bindtap="triggers" data-idType="1">点击我</view>
注意:
data-是固定的写法,-后面可以取任意的名字,但是需要强调的是在获取的时候要写相对应的名字,例如:data-index = "1",获取时就是e.target.dataset.index。
下面通过一个简单的代码小实例带大家更直观的了解 data- 的用法。
wxml文件
<!-- 按钮触发事件 -->
<view bindtap="triggers" data-idType="1">点击我</view>
js文件
Page({
data: {
},
//点击事件
triggers(e) {
console.log(e.target.dataset.idtype); // 1
},
})
如下图:

边栏推荐
- 谈谈数字化转型的几个关键问题
- 顺祝老吴的聚会
- Modify the name of the launched applet
- Gartner focuses on low code development in China how UNIPRO practices "differentiation"
- 严格次小生成树
- 去中心化交易所系统开发技术原理丨数字货币去中心化交易所系统开发(说明案例)
- Go language learning notes - Gorm usage - database configuration, table addition | web framework gin (VII)
- MFC interface library bcgcontrolbar v33.0 - desktop alarm window, grid control upgrade, etc
- Failed to configure a DataSource: ‘url‘ attribute is not specified and no embedded datasource could
- About, Qianxin detects code vulnerabilities and XSS series solves them
猜你喜欢

牛逼|珍藏多年的工具让我实现了带薪摸鱼自由
![[micro service ~nacos] configuration center of Nacos](/img/c3/9d8fb0fd49a0ebab43ed604f9bd1cc.png)
[micro service ~nacos] configuration center of Nacos

JVM Part 21 of interview with big companies Q & A

10 airbags are equipped as standard, and Chery arizer 8 has no dead corner for safety protection
![[career planning for Digital IC graduates] Chap.1 overview of IC industry chain and summary of representative enterprises](/img/d3/68c9d40ae6e61efc10aca8bcc1f613.jpg)
[career planning for Digital IC graduates] Chap.1 overview of IC industry chain and summary of representative enterprises

Pytorch quantitative practice (1)

PostgreSQL存储结构浅析
![[BSP video tutorial] BSP video tutorial issue 19: AES encryption practice of single chip bootloader, including all open source codes of upper and lower computers (June 26, 2022)](/img/ce/9ec74c4c26513e2479df29a1802168.png)
[BSP video tutorial] BSP video tutorial issue 19: AES encryption practice of single chip bootloader, including all open source codes of upper and lower computers (June 26, 2022)

Introduction to go web programming: a probe into the excellent test library gocovey

【BSP视频教程】BSP视频教程第19期:单片机BootLoader的AES加密实战,含上位机和下位机代码全开源(2022-06-26)
随机推荐
「团队训练赛」ShanDong Multi-University Training #3
Best wishes for Lao Wu's party
Pytorch quantitative practice (2)
十个最为戳心测试/开程序员笑话,念茫茫人海,该如何寻觅?
Femas: cloud native multi runtime microservice framework
B_ QuRT_ User_ Guide(32)
深入解析 Apache BookKeeper 系列:第四篇—背压
Is there a shortage? No need to download the free online resources! 2022 favorites must have it!
Online education program user login and registration
Interesting plug-ins summary
KVM IO性能测试数据
Where can I find the computer version of wechat files
Niubi | the tools I have treasured for many years have made me free to fish with pay
B_ QuRT_ User_ Guide(35)
AtCoder Beginner Contest 255
B_ QuRT_ User_ Guide(31)
100 important knowledge points that SQL must master: creating and manipulating tables
Gartner focuses on low code development in China how UNIPRO practices "differentiation"
Stimulate new kinetic energy to develop digital economy in multiple places
Develop technology - get time 10 minutes ago