1.catchtap点击事件(与bindtap相比 可阻止冒泡) data-id 后面是你要传递的东西
<view class="goods" wx:for='{{goodsList}}' wx:key="ORDER_CODE" catchtap="toGoodsDetail" data-id="{{item.ID}}">
2.点击事件通过e(event)来获取传递的值
---微信小程序js文件
toGoodsDetail(e){
// console.log(e);
var ID = e.currentTarget.dataset.id;
wx.navigateTo({
//动态路由传参
url: '../../pages/goodsdetail/index?ID='+ID,
})
},
3.跳转到的页面通过onLoad 函数(option)接收传递过来的值
/**
* 生命周期函数--监听页面加载
*/
onLoad: function (options) {
var ID = options.ID
},
4.拿到值后就可以进行页面渲染了, 前端小白白欢迎大佬指点!