tabbar版本 重新进来,不会停留在上一次的页面上,但是底下的tabbar会在上一次的地方高亮。
/src/components/fg-tabbar/fg-tabbar.vue
建议在这里优化下代码
原代码:
function selectTabBar({ value: index }: { value: number }) { // const url = tabbarList[index].path // tabbarStore.setCurIdx(index) // uni.switchTab({ url }) doSelTabBar(index) } const doSelTabBar = (index: number) => { const url = tabbarList[index].path tabbarStore.setCurIdx(index) uni.switchTab({ url }) } onLoad(() => { // 解决原生 tabBar 未隐藏导致有2个 tabBar 的问题 // #ifdef APP-PLUS | H5 uni.hideTabBar({ fail(err) { console.log('hideTabBar fail: ', err) }, success(res) { console.log('hideTabBar success: ', res) }, }) // #endif // add by xmvigour 重新进入的时候进入上一次的tab if (tabbarStore.curIdx > 0) { // selectTabBar(tabbarStore.curIdx) doSelTabBar(tabbarStore.curIdx) console.log('tabbarStore.curIdx', tabbarStore.curIdx) } })
改完以后:(onload坐一下判断 )
function selectTabBar({ value: index }: { value: number }) { // const url = tabbarList[index].path // tabbarStore.setCurIdx(index) // uni.switchTab({ url }) doSelTabBar(index) } const doSelTabBar = (index: number) => { const url = tabbarList[index].path tabbarStore.setCurIdx(index) uni.switchTab({ url }) } onLoad(() => { // 解决原生 tabBar 未隐藏导致有2个 tabBar 的问题 // #ifdef APP-PLUS | H5 uni.hideTabBar({ fail(err) { console.log('hideTabBar fail: ', err) }, success(res) { console.log('hideTabBar success: ', res) }, }) // #endif // add by xmvigour 重新进入的时候进入上一次的tab if (tabbarStore.curIdx > 0) { // selectTabBar(tabbarStore.curIdx) doSelTabBar(tabbarStore.curIdx) console.log('tabbarStore.curIdx', tabbarStore.curIdx) } })
兄弟,提个PR 吧,新仓库用 codercup2/unibest, 在新仓库里面提。