微信小程序tab點擊監聽方法:onTabItemTap()
在頁面沒有獲取user或者沒有登陸成功的時候,再page頁面(首頁)點擊任何功能都讓其返回登陸頁面,可以用onTabItemTap()函數進行控制。
onTabItemTap() {
let self = this
if (!wx.getStorageSync('user')) {
wx.showModal({
title: '提示',
content: '賬號尚未登錄,請先登錄賬號',
success: res => {
if (res.confirm) {
wx.navigateTo({
url: '/pages/login/login'
})
} else if (res.cancel) {
wx.reLaunch({
url: '/pages/main/homePage'
})
}
}
})
}
},
實戰項目知識小積累,也希望幫助到有需要的你們,也歡迎大家來吐槽。