Browse Source

🎈 perf(tabbar): 导航栏和路由联动

陈雪 3 weeks ago
parent
commit
a2160c3916
2 changed files with 11 additions and 0 deletions
  1. 10 0
      src/components/shop-tabbar/shop-tabbar.vue
  2. 1 0
      src/store/tabbar.ts

+ 10 - 0
src/components/shop-tabbar/shop-tabbar.vue

@@ -86,6 +86,16 @@
         console.log('hideTabBar success: ', res)
       },
     })
+    const routes = getCurrentPages()
+    const curRoute = routes[routes.length - 1].route
+    for (let i = 0; i < tabBar.list.length; i++) {
+      const { pagePath } = tabBar.list[i]
+      if (pagePath === curRoute) {
+        tabbarStore.setCurIdx(i)
+        break
+      }
+    }
+
     // #endif
   })
 </script>

+ 1 - 0
src/store/tabbar.ts

@@ -8,6 +8,7 @@ export const useTabbarStore = defineStore('tabbar', {
   actions: {
     setCurIdx(idx: number) {
       this.tabbarIndex = idx
+      uni.setStorageSync('app-tabbar-index', idx)
     },
   },
   getters: {