当前位置:网站首页>微信小程序通过点击事件传参(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
},
})
如下图:

边栏推荐
- Pytorch quantitative practice (1)
- Label Contrastive Coding based Graph Neural Network for Graph Classification
- Anfulai embedded weekly report no. 271: June 20, 2022 to June 26, 2022
- Coredns modifying upstream
- Is it difficult to get a certified equipment supervisor? What is the relationship with the supervising engineer?
- 机器学习中如何使用数据集?
- Uniapp rich text editor
- leetcode:104. 二叉树的最大深度
- Cas classique multithreadé
- 分享十万级TPS的IM即时通讯综合消息系统的架构
猜你喜欢

B_ QuRT_ User_ Guide(31)

latex左侧大括号 latex中大括号多行公式

Some memory problems summarized

Is Wu Enda's machine learning suitable for entry?

深入解析 Apache BookKeeper 系列:第四篇—背压

Web APIs comprehensive case -tab column switching - dark horse programmer

Zhoushaojian, rare

RP prototype resource sharing - shopping app

Introduction and example of template method mode

On several key issues of digital transformation
随机推荐
latex左侧大括号 latex中大括号多行公式
The Three Musketeers: One for All!
Yolo target detection
Do a scrollbar thinking
Analysis of doctor Aifen's incident
Architecture of IM integrated messaging system sharing 100000 TPS
Analyse des risques liés aux liaisons de microservices
艾芬医生事件解析
国产数据库乱象
Stimulate new kinetic energy to develop digital economy in multiple places
How to develop the exchange system? Mature technology case of digital currency exchange system development
多線程經典案例
Is it difficult to get a certified equipment supervisor? What is the relationship with the supervising engineer?
Analysis of PostgreSQL storage structure
请指教同花顺软件究竟是什么?另外想问,现在在线开户安全么?
msf之ms17-010永恒之蓝漏洞
Go language learning notes - Gorm usage - database configuration, table addition | web framework gin (VII)
Online education program user login and registration
微服務鏈路風險分析
顺祝老吴的聚会