//传参
//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,
})