可以看出 参数是通过给标签设置 data-参数名=“参数值” 自定义属性的方式 来传递的 例如想传递两个参数
//index.wxml view bindtap="changeIndex" data-src1="我固定参数1" data-src2="我是固定参数2" /view //index.js page({ data:{ changeIndex(e){ console.log(e.currentTarget.dataset.src1); //我是固定参数1 console.log(e.currentTarget.dataset.src2); //我是固定参数2 });
如果需要传递动态的参数 例如遍历渲染时 想传递 index 给 changeIndex方法
//index.wxml view wx:for="{{lists}}" wx:for-index="index" wx:key="index" data-index="{{index}}" {{item.title}} /view //index.js page({ data:{ lists:[{title:'参数1',id:1},{title:'参数2',id:2}] changeIndex(e){ console.log(e.currentTarget.dataset.index); })
知识点补充:
微信小程序:bindtap方法传参
1、wxml
view bindtap="pay_again" data-name="{{orderList.jid}}" data-fee="{{orderList.act_fee}}" data-mobile="{{orderList.p_phone}}" data-act="{{orderList.act_name}}" a href="" external nofollow" pay bg_red" 继续支付 /a /view
2、js
// 再次发起支付请求,调用后台PHP pay_again:function(e){ var that = this; that.setData({ jid: e.currentTarget.dataset.name, act_name: e.currentTarget.dataset.act, act_fee: e.currentTarget.dataset.fee, mobile: e.currentTarget.dataset.mobile console.log('活动订单id = ' + that.data.mobile); }
总结
到此这篇关于微信小程序 bindtap 传参的实例代码的文章就介绍到这了,更多相关微信小程序 bindtap 传参内容请搜素凡科以前的文章或下面
手机微信微信小程序 bindtap 传参的案例编码 本文关键详细……
easyUI应用分页查询过虑器多数据开展分页查询实际操作案例剖析……
处理vue部件消毁以后记时器再次实行的难题 本文关键详细……
JavaScript部位主要参数完成基本原理及全过程分析 本文关键……
[db:摘要]……
前端开发特性提升填补篇 公布 序言 基本提升 1、switch句子……