微信小程序 bindtap 传参的实例代码
更新时间:2020年02月21日 16:55:06 作者:皮的狠
这篇文章主要介绍了微信小程序 bindtap 传参的实例代码,代码简单易懂,非常不错,具有一定的参考借鉴价值,需要的朋友可以参考下
微信小程序 bindtap 传参 ,代码如下所示:
//index.wxml
<view bindtap="changeIndex" data-src="我固定参数">
</view>
//index.js
page({
data:{
},
changeIndex(e){
console.log(e.currentTarget.dataset.src); //我是固定参数
}
});
可以看出 参数是通过给标签设置 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}}" class="operating f_r webkit-box" style="line-height:30px;">
<a href="" class=" rel="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 传参内容请搜素脚本之家以前的文章或下面相关文章,希望大家以后多多支持脚本之家!
相关文章
详解webpack的clean-webpack-plugin插件报错
这篇文章主要介绍了详解webpack的clean-webpack-plugin插件报错,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧2020-10-10


最新评论