Error in v-on handler: "TypeError: Cannot read property 'id' of undefined"

出现这个错误 就是因为state中tabs数组中有id是有问题的,我都把每个变量打印出来,看看到执行到哪一步出现报错。
问题就在,当添加相同的 ‘导入模板’就会出现报错,
解决办法,如果tabs中有当前添加的项,就让他return出来,如果tabs中没有 就触发函数 addAsync()

const index1 = state.tabs.findIndex(item => {
        return item.id === tabId  //tabId就是当前要添加项的id
      }) 
      if (index1 === -1) {
        targetTab.time = currTime
        commit('addTab', targetTab)
      } else {
        return
        // state.tabs[index1].time = currTime
        // commit('setTab', index1, state.tabs[index1])
      }
发布了24 篇原创文章 · 获赞 2 · 访问量 9178

猜你喜欢

转载自blog.csdn.net/sunmeng_sunmeng/article/details/103714944