微信小程序bindtap传参的实例代码

  

微信小程序bindtap传参,代码如下所示:

     //index.wxml   & lt;视图bindtap=" changeIndex " data-src=" https://www.yisu.com/zixun/我固定参数”比;   & lt;/view>//index.js   页面({   数据:{   },   changeIndex (e) {   console.log (e.currentTarget.dataset.src);//我是固定参数   }   });      

可以看出参数是通过给标签设置数据——参数名="参数值“自定义属性的方式来传递的例如想传递两个参数

     //index.wxml   & lt;视图bindtap=" changeIndex " data-src1=拔夜潭ú问?”data-src2=拔沂枪潭ú问?”在      & lt;/view>//index.js   页面({   数据:{      },   changeIndex (e) {   console.log (e.currentTarget.dataset.src1);//我是固定参数1   console.log (e.currentTarget.dataset.src2);//我是固定参数2   }   });      

如果需要传递动态的参数例如遍历渲染时想传递指数给changeIndex方法

     //index.wxml   & lt;观点wx:="{{列表}}”天气:对于指数=爸甘钡奶炱?关键=爸甘辈牧现甘?皗{指数}}”比;   {{item.title}}   & lt;/view>//index.js   页面({   数据:{   列表:[{标题:“参数1 ',id: 1},{标题:“参数2》,id: 2}]   },   changeIndex (e) {   console.log (e.currentTarget.dataset.index);   }   })      

  

  

1, wxml         & lt;视图bindtap=数据名=" {{orderList“pay_again”。jid}} {{orderList data-fee=ct_fee}} {{orderList data-mobile=_phone}} {{orderList“数据操作=薄ct_name}}”class="操作f_r webkit-box”比;   & lt; a href=" class=" rel="外部nofollow”支付bg_red祝辞继续支付& lt;/a>   & lt;/view>   之前      

2, js      //再次发起支付请求,调用后台PHP   pay_again:函数(e) {   var=这个;   that.setData ({   jid: e.currentTarget.dataset.name,   act_name: e.currentTarget.dataset.act,   act_fee: e.currentTarget.dataset.fee,   手机:e.currentTarget.dataset.mobile   })   控制台。日志(“活动订单id=" + that.data.mobile);   }      

<强>

  

到此这篇关于微信小程序bindtap传参的实例代码的文章就介绍到这了,更多相关微信小程序bindtap传参内容请搜素以前的文章或下面相关文章,希望大家以后多多支持!

微信小程序bindtap传参的实例代码