微信小程序 bindtap 傳參的實例代碼
微信小程序 bindtap 傳參 ,代碼如下所示:
//index.wxml
<view bindtap="changeIndex" data-src="我固定參數(shù)">
</view>
//index.js
page({
data:{
},
changeIndex(e){
console.log(e.currentTarget.dataset.src); //我是固定參數(shù)
}
});
可以看出 參數(shù)是通過給標簽設(shè)置 data-參數(shù)名=“參數(shù)值” 自定義屬性的方式 來傳遞的 例如想傳遞兩個參數(shù)
//index.wxml
<view bindtap="changeIndex" data-src1="我固定參數(shù)1" data-src2="我是固定參數(shù)2" >
</view>
//index.js
page({
data:{
},
changeIndex(e){
console.log(e.currentTarget.dataset.src1); //我是固定參數(shù)1
console.log(e.currentTarget.dataset.src2); //我是固定參數(shù)2
}
});
如果需要傳遞動態(tài)的參數(shù) 例如遍歷渲染時 想傳遞 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:'參數(shù)1',id:1},{title:'參數(shù)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">繼續(xù)支付</a>
</view>
2、js
// 再次發(fā)起支付請求,調(diào)用后臺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);
}
總結(jié)
到此這篇關(guān)于微信小程序 bindtap 傳參的實例代碼的文章就介紹到這了,更多相關(guān)微信小程序 bindtap 傳參內(nèi)容請搜素腳本之家以前的文章或下面相關(guān)文章,希望大家以后多多支持腳本之家!
相關(guān)文章
JS實現(xiàn)快速比較兩個字符串中包含有相同數(shù)字的方法
這篇文章主要介紹了JS實現(xiàn)快速比較兩個字符串中包含有相同數(shù)字的方法,涉及javascript字符串的遍歷、排序、比較等相關(guān)操作技巧,需要的朋友可以參考下2017-09-09
原生js實現(xiàn)fadein 和 fadeout淡入淡出效果
這篇文章主要介紹了通過原生js實現(xiàn)fadein 和 fadeout淡入淡出效果,需要的朋友可以參考下2014-06-06
詳解webpack的clean-webpack-plugin插件報錯
這篇文章主要介紹了詳解webpack的clean-webpack-plugin插件報錯,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧2020-10-10

