錯誤如下
拿到公司一個小哥哥的代碼,一來就報了一堆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" />