微信小程序的传参与带参跳转

//传参
//xxx.wxml(在wxml中定义一个函数,通过data-xxx=" ",绑定你需要传过来的东西)
<view class="gridContent">
       <van-grid column-num="4" class="grid" border="{{ false }}">      
      <van-grid-item icon="{{item.iconUrl}}" text="{{item.name}}" wx:for="{{Category}}"       
wx:key="{{index}}" bindtap="gotoCategory" data-index="{{item.categoryId}}"/>
      
   
        </van-grid>
    </view>
//接收
//xxx.js
  gotoCategory:function(options){
    //根据传过来的分类Id传过去
    console.log("分类的Id=====", options.currentTarget.dataset.index)
    // 把获取商品分类的Id赋值给全局的变量,我们想要在下一页获取参数,直接获取就行,注意不能把参数放在url中
    app.$categoryId= options.currentTarget.dataset.index

    console.log(" app.$categoryId", app.$categoryId)
    // 普通页面跳转
    console.log("options", options)   
    wx.switchTab({
      url: '/pages/category/category',
  })

  }

带参跳转

      wx.navigateTo({
        url: '/pages/order/orderConfirm/index?preOrderId=' + res.result.preOrderId,
      })

页面接收

//跳转过来页面的js中接收
 onLoad: function (options) {
    this.setData({
      preOrderId: options.preOrderId,
      
    })
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。