温馨提示×

微信小程序页面间如何传id

小新
242
2021-03-19 16:30:32
栏目: 云计算

微信小程序页面间如何传id

微信小程序页面间传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 })

 },

0