Browse Source

fix(tabbar): resolve href error #1533 (#1556)

Drjingfubo 3 years ago
parent
commit
39d839ec62
2 changed files with 15 additions and 19 deletions
  1. 3 5
      src/packages/__VUE/tabbaritem/index.taro.vue
  2. 12 14
      src/packages/__VUE/tabbaritem/index.vue

+ 3 - 5
src/packages/__VUE/tabbaritem/index.taro.vue

@@ -140,11 +140,9 @@ export default create({
           return item.name == value;
         });
       }
-      setTimeout(() => {
-        if (parent.children[index].href) {
-          window.location.href = parent.children[index].href;
-        }
-      });
+      if (parent.children[index]?.href) {
+        window.location.href = parent.children[index].href;
+      }
     });
     return {
       state,

+ 12 - 14
src/packages/__VUE/tabbaritem/index.vue

@@ -139,24 +139,22 @@ export default create({
       state.active = value;
       let index = value;
       if (props.name) {
-        index = parent.children.findIndex((item: any) => {
+        index = parent.children.findIndex((item: { name: string | number }) => {
           return item.name == value;
         });
       }
-      setTimeout(() => {
-        if (parent.children[index].href) {
-          window.location.href = parent.children[index].href;
-          return;
-        }
-        if (parent.children[index].to) {
-          let to = parent.children[index].to;
-          if (to && router) {
-            router.push(to);
-          } else {
-            location.replace(to);
-          }
+      if (parent.children[index]?.href) {
+        window.location.href = parent.children[index].href;
+        return;
+      }
+      if (parent.children[index]?.to) {
+        let to = parent.children[index].to;
+        if (to && router) {
+          router.push(to);
+        } else {
+          location.replace(to);
         }
-      });
+      }
     });
     return {
       state,