先在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 /><br />获取参数:
btclick2(e){
console.log(e.target.dataset.name);
console.log(e.target.dataset.wx);
}
输出结果<br />