- Preface
Recently I am working on a submission applet. The main function is that authors can log in, register, and then log in to the main page of the WeChat applet. They can submit manuscripts and browse their submitted manuscripts, as well as personal center and other main functions. It is relatively simple to do. Because I am a beginner in small programs.
- Problems encountered:
The login page is not a tabBar page, it is just a normal page, and I want to jump to the tabBar homepage after logging in. How can I jump from picture 1 to picture 2?
Figure 1
Figure 2
- Solution: View the official documentation. You can use the api wx.reLaunch()
provided by the WeChat applet. This method can not only jump from non-tabBar pages to non-tabBar pages, but also carry parameters.
Login part js code:
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);
}
})
}