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

边栏推荐
- Label Contrastive Coding based Graph Neural Network for Graph Classification
- [450. delete nodes in binary search tree]
- Online education program user login and registration
- About, Qianxin detects code vulnerabilities and XSS series solves them
- Installing jupyter notebook under Anaconda
- Ten of the most heart piercing tests / programmer jokes, read the vast crowd, how to find?
- [introduction to MySQL] the first conversation · first time in the "database" Mainland
- Golang application ━ installation, configuration and use of Hugo blog system
- Is Wu Enda's machine learning suitable for entry?
- Windbg调试工具介绍
猜你喜欢

MFC interface library bcgcontrolbar v33.0 - desktop alarm window, grid control upgrade, etc

Vite2 is compatible with lower versions of chrome (such as Sogou 80). Some grammars requiring higher versions are processed through polyfills

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

How to change the win11 computer name? Win11 method of changing computer name

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

Win11电脑名如何更改?Win11更改电脑名的方法

Mysql:sql overview and database system introduction | dark horse programmer
Notes [introduction to JUC package and future]

Where can I find the computer version of wechat files

How to upload binary pictures in uniapp
随机推荐
Introduction to go web programming: a probe into the excellent test library gocovey
"Trust machine" empowers development
Analysis of PostgreSQL storage structure
软件确认测试的内容和流程有哪些?确认测试报告需要多少钱?
分享十万级TPS的IM即时通讯综合消息系统的架构
Vite2 is compatible with lower versions of chrome (such as Sogou 80). Some grammars requiring higher versions are processed through polyfills
Where can I find the computer device manager
【MySQL入门】第一话 · 初入“数据库”大陆
WinDbg debugging tool introduction
latex中 & 号什么含义?
leetcode:104. 二叉树的最大深度
PostgreSQL存储结构浅析
Gartner focuses on low code development in China how UNIPRO practices "differentiation"
The Sandbox 正在 Polygon 网络上进行部署
Spark - understand partitioner in one article
How to use filters in jfinal to monitor Druid for SQL execution?
KVM IO performance test data
[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)
2022-06-30:以下golang代码输出什么?A:0;B:2;C:运行错误。 package main import “fmt“ func main() { ints := make
I want to know who I need to know to open a stock account? In addition, is it safe to open a mobile account?