Browse Source

fix(tabs): 父组件默认值传入时无法更新tabs当前标签状态 #832

richard1015 4 years ago
parent
commit
90197d0a23
2 changed files with 4 additions and 6 deletions
  1. 2 3
      src/packages/__VUE/tabs/index.taro.vue
  2. 2 3
      src/packages/__VUE/tabs/index.vue

+ 2 - 3
src/packages/__VUE/tabs/index.taro.vue

@@ -90,7 +90,7 @@ export default create({
   setup(props, { emit, slots }) {
     provide('activeKey', { activeKey: computed(() => props.modelValue) });
     const titles: Ref<Title[]> = ref([]);
-    const currentIndex = ref(0);
+    const currentIndex = ref((props.modelValue as number) || 0);
 
     const renderTitles = (vnodes: VNode[]) => {
       vnodes.forEach((vnode: VNode, index: number) => {
@@ -132,8 +132,7 @@ export default create({
         } else {
           currentIndex.value = index;
         }
-      },
-      { immediate: true }
+      }
     );
     onMounted(init);
     onActivated(init);

+ 2 - 3
src/packages/__VUE/tabs/index.vue

@@ -86,7 +86,7 @@ export default create({
   setup(props, { emit, slots }) {
     provide('activeKey', { activeKey: computed(() => props.modelValue) });
     const titles: Ref<Title[]> = ref([]);
-    const currentIndex = ref(0);
+    const currentIndex = ref((props.modelValue as number) || 0);
 
     const renderTitles = (vnodes: VNode[]) => {
       vnodes.forEach((vnode: VNode, index: number) => {
@@ -128,8 +128,7 @@ export default create({
         } else {
           currentIndex.value = index;
         }
-      },
-      { immediate: true }
+      }
     );
     onMounted(init);
     onActivated(init);