Vue中Duplicate keys detected錯誤


錯誤如下

拿到公司一個小哥哥的代碼,一來就報了一堆bug,嚇得我先寫一篇博客

vue.runtime.esm.js?2b0e:619 [Vue warn]: Duplicate keys detected: '/system'. This may cause an update error.

found in

---> <Sidebar> at src/layout/components/Sidebar/index.vue
       <Layout> at src/layout/index.vue
         <App> at src/App.vue
           <Root>
  • 原因:v-for時,key值不唯一(一般出現在 v-for循環生成列表,對key值處理不當時)
  • 下列代碼一可以修改route.path,但是項目急着要,所以就先加了一個前綴index處理
    原代碼:
<sidebar-item v-for="(route, index) in permission_routes" :key="route.path" :item="route" :base-path="route.path" />  
  • 解決:
<sidebar-item v-for="(route, index) in permission_routes" :key="index + route.path" :item="route" :base-path="route.path" />


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM