- 前言
最近在做一個投稿小程序,主要功能是作者可以在微信小程序登錄,注冊,然后登陸進入主頁面,可以投遞稿件以及瀏覽自己已投遞的稿件,和個人中心等主要功能,做的比較簡單,因為本人對于小程序是一個初學者。
- 遇到的問題
登錄頁面不是tabBar頁面,只是一個普通頁面,而我想通過登錄之后可以跳轉(zhuǎn)到tabBar首頁,圖一怎么跳轉(zhuǎn)到圖二呢?
圖一
圖二文章來源:http://www.zghlxwxcb.cn/news/detail-718219.html
- 解決思路
查看官方文檔,可以通過微信小程序提供的api
wx.reLaunch()
這種方式不僅可以從非tabBar頁面跳轉(zhuǎn)到非tabBar頁面,還可以攜帶參數(shù)
登錄部分js代碼:文章來源地址http://www.zghlxwxcb.cn/news/detail-718219.html
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{
// 登錄成功后,設(shè)置全局變量-username
const app = getApp();
app.globalData.username = username
wx.reLaunch({
url: '/pages/index/index?username='+username,
})
}
},
fail: (error) => {
//console.log('請求失敗:', error);
}
})
}
到了這里,關(guān)于微信小程序之普通頁面跳轉(zhuǎn)到tabBar頁面的文章就介紹完了。如果您還想了解更多內(nèi)容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!