Kaynağa Gözat

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

陈雪 3 hafta önce
ebeveyn
işleme
a2160c3916

+ 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: {