瀏覽代碼

fix: 修复切换逻辑问题

zhangyuhan 1 年之前
父節點
當前提交
2d26ba0354
共有 1 個文件被更改,包括 4 次插入2 次删除
  1. 4 2
      src/custom-tab-bar/index.vue

+ 4 - 2
src/custom-tab-bar/index.vue

@@ -43,10 +43,12 @@ export default {
     ...mapGetters('tabbar', ['activeTabKey', 'tabbars'])
     ...mapGetters('tabbar', ['activeTabKey', 'tabbars'])
   },
   },
   methods: {
   methods: {
+    ...mapMutations('tabbar', ['setSwitchTab']),
     ...mapActions('tabbar', ['doSwitchTab']),
     ...mapActions('tabbar', ['doSwitchTab']),
     checkActiveTabbar ()  {
     checkActiveTabbar ()  {
-      const activeKey = this.getComputedActiveKey(this.activeTabKey || this.tabbars[0].key)
-      this.doSwitchTab(activeKey)
+      const defaultKey = this.activeTabKey || (this.tabbars[0] ? this.tabbars[0].key : '')
+      const activeKey = this.getComputedActiveKey(defaultKey)
+      this.setSwitchTab(activeKey)
     },
     },
     getComputedActiveKey (defaultActive = '') {
     getComputedActiveKey (defaultActive = '') {
       let active = defaultActive
       let active = defaultActive