微信小程序中如何携带参数跳转到tabBar页面

  • Post author:
  • Post category:小程序


在小程序中使用了tabBar组件之后就不能用wx.navigateTo跳转到tabBar页面了 , 能跳转到tabBar页面的方法有以下两种

1、wx.switchTab

2、wx.reLaunch

但是使用第一种方法时,会因为这种方法在路径后不能携带参数,所以行不通,那么就只能用第二种方法 , 用wx.reLaunch进行跳转 , 地址后跟上自己想要的参数 , 或者用wx.setStorage将想要的参数存到内存中去 , 在下个页面中直接用wx.getStroge去内存中取出

getInfo(){
    let that = this;
    wx.request({
      url: this.data.baseURL+'/user/info?token='+this.data.token,
      success (res) {
        that.setData({
            info:userinfo
        })
        wx.setStorage({
          data: res.data.data.id,
          key: 'id',
        })
        wx.setStorage({
          data: res.data.data.name,
          key: 'name',
        })
        wx.setStorage({
          data: res.data.data.avatar,
          key: 'avatar',
        })
        // 用了tabBar之后,不能用wx.navigateTo
        wx.reLaunch({
          url:'../user/user?userinfo='+that.data.info
        })
      }
    })
  },

原文链接:https://blog.csdn.net/weixin_46363283/article/details/106716436