当前位置:   article > 正文

微信小程序之普通页面跳转到tabBar页面_微信小程序跳转tabbar页面

微信小程序跳转tabbar页面
  • 前言

最近在做一个投稿小程序,主要功能是作者可以在微信小程序登录,注册,然后登陆进入主页面,可以投递稿件以及浏览自己已投递的稿件,和个人中心等主要功能,做的比较简单,因为本人对于小程序是一个初学者。

  • 遇到的问题
    登录页面不是tabBar页面,只是一个普通页面,而我想通过登录之后可以跳转到tabBar首页,图一怎么跳转到图二呢?

在这里插入图片描述图一
在这里插入图片描述
图二

  • 解决思路
    查看官方文档,可以通过微信小程序提供的api
    wx.reLaunch()在这里插入图片描述
    这种方式不仅可以从非tabBar页面跳转到非tabBar页面,还可以携带参数

登录部分js代码:

doLogin(){
    let username = this.data.username;
    let password = this.data.password;
    if(username == '' || password == ''){
      wx.showToast({
        title: '登录失败',
        icon: 'error'
      })
      return;
    }
    wx.request({
      url: 'http://localhost:8082/onlineSubmit/system/login',
      method: 'POST',
      header: {
        "content-type":"application/x-www-form-urlencoded"
      },
      data: {
        username: username,
        password: password,
        type: this.data.type
      },
      success:(res)=>{
        console.log(res.data);
        if(res.data.type == 'error'){
          wx.showToast({
            title: '用户不存在!',
            icon:'error'
          })
        }else{
          // 登录成功后,设置全局变量-username
          const app = getApp();
          app.globalData.username = username
          wx.reLaunch({
            url: '/pages/index/index?username='+username,
          })
        }
      },
      fail: (error) => {
        //console.log('请求失败:', error);
      }
    })
  }
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/我家自动化/article/detail/94007
推荐阅读