先在index.wxml 文件中添加
<!-- data-xxx 设置传递的参数,后面的xxx可以自定义-->
<button type="primary" bindtap="btclick2" data-name="liuxin" data-wx="2928527233">事件传参</button>
然后在 index.js 中接收这个参数
btclick2(e){
console.log(e);
}
接收到JSON:<br />![image.png](https://cdn.nlark.com/yuque/0/2022/png/26240361/1646018550986-76e1e30e-7575-4942-a636-467afba21425.png#clientId=u85cabd39-f946-4&crop=0&crop=0&crop=1&crop=1&from=paste&height=182&id=u9db8be98&margin=%5Bobject%20Object%5D&name=image.png&originHeight=363&originWidth=937&originalType=binary&ratio=1&rotation=0&showTitle=false&size=29238&status=done&style=none&taskId=u013969f2-8b8b-4e43-bbe4-16847300dba&title=&width=468.5)<br />获取参数:
btclick2(e){
console.log(e.target.dataset.name);
console.log(e.target.dataset.wx);
}
输出结果<br />![image.png](https://cdn.nlark.com/yuque/0/2022/png/26240361/1646018595689-cae64cd5-2c3a-410d-a75d-c0f3f5b358b0.png#clientId=u85cabd39-f946-4&crop=0&crop=0&crop=1&crop=1&from=paste&height=75&id=u1b35c5f0&margin=%5Bobject%20Object%5D&name=image.png&originHeight=150&originWidth=637&originalType=binary&ratio=1&rotation=0&showTitle=false&size=6429&status=done&style=none&taskId=uee894847-bb42-4620-9df6-01beedfee7e&title=&width=318.5)