微信小程序点击事件传参形式和传统的原生点击事件传参略有差别,点击事件属性为“bindtap”,bindtap属性接收一个方法名称(例如 bingtap="testFunction"),但是不支持testFunction("id")的形式传递参数值function,小程序中新增了data-*属性值用于绑定对应参数;在指定testFunction方法中通过e.currentTarget.dataset.*来获取对应的参数后再进行后续逻辑处理。具体代码案例如下:
<view class="itpmpcard" bindtap="openDetail" data-apply="{{apply}}">
点击我验证参数传递
</view>
openDetail: function (e) {
let apply = e.currentTarget.dataset.apply
console.log(apply)
},