1、data-*指令:传递wxml页面数据至后台js
wxml代码
<view class='container'> <view class='nav_left'> <block wx:for="{{navLeftItems}}" wx:key="id"> <view class='nav_left_items' bindtap='switchItem' data-id="{{item.id}}"> {{item.categoryName}} </view> </block> </view> </view> |
js代码:通常event参数获取需要传递的data-*参数
switchItem: function(event) { console.log(event.target.dataset.id); } |
2、微信小程序获取url传参
跳转函数
navigateToProducts: function (event) { const searchName = event.target.dataset.name || ''; wx.redirectTo({ url: `../product_list/product_list?name=${searchName}`, }); } |
获取url参数函数
onLoad: function (options) { this.setData({ searchName: options.name, }); } |