微信小程序跳转tabBar页面传参

微信小程序底部tabBar一般通过wx.switchTab进行跳转,但该api无法传参,如何解决传参问题?

网上查了一下,一般都是通过app.globalData全局变量进行传参的,但这种方法在需要配置公众号菜单跳转到微信小程序且需要带参的情况下的情况,显得不是那么方便。其实还有另一种方法,就是通过wx.reLaunch进行跳转,它也可以跳转到tabBar,且可以传参,当然注意它会关闭其他页面。个人认为wx.reLaunch是比较好的处理方式。

代码实例和官方文档如下:https://developers.weixin.qq.com/miniprogram/dev/api/route/wx.switchTab.html

  reLaunch() {
    wx.reLaunch({
      url: `/pages/index/index?brand_name=${this.data.brand_name}&name=${this.data.names}&price=${this.data.price}&size=${this.data.size}&money=${this.data.num}&cashPledge=${this.data.cashPledge}`,//传递给tabBar的参数
      success: (res) => {
        console.log('成功传送',res);
      }
    })
  },

猜你喜欢

转载自blog.csdn.net/cx1361855155/article/details/128299028