小程序獲取當前頁面id的案例:
.wxml文件代碼:
<block wx:for-items="{{newGoods}}" wx:key="id">
<view catchtap="catchTapCategory" data-goodsid="{{item.id}}">
<view>
<image src="{{item.imgUrl}}" />
</view>
<view class="product-name">
{{item.name}}
</view>
</view>
</block>
.js文件代碼:
catchTapCategory: function (e) {var that = this;
var goodsId = e.currentTarget.dataset.goodsid;
console.log('goodsId:' + goodsId);
wx.navigateTo({ url: '../detail/detail?goodsId=' + goodsId })
},