Explorar o código

fix(tabbar): 修复未匹配路由时默认选中第一个标签的问题

当当前页面路由不在标签栏配置中时,检查是否在页面栈中存在匹配路由,避免直接选中第一个标签
feige996 hai 8 meses
pai
achega
b184adc9a3
Modificáronse 1 ficheiros con 7 adicións e 1 borrados
  1. 7 1
      src/tabbar/store.ts

+ 7 - 1
src/tabbar/store.ts

@@ -40,7 +40,13 @@ const tabbarStore = reactive({
     console.log('index:', index, path)
     // console.log('tabbarList:', tabbarList)
     if (index === -1) {
-      this.setCurIdx(0)
+      const pagesPathList = getCurrentPages().map(item => item.route.startsWith('/') ? item.route : `/${item.route}`)
+      // console.log(pagesPathList)
+      const flag = tabbarList.some(item => pagesPathList.includes(item.pagePath))
+      if (!flag) {
+        this.setCurIdx(0)
+        return
+      }
     }
     else {
       this.setCurIdx(index)