Vue
vue/require-v-for-key
Every v-for gives its items a :key from the data; on a template v-for the key goes on the template tag.
umiarkowanastatycznefe-vue
Dlaczego
Without a key, Vue patches list items in place by position. When the list is sorted, filtered or an item is inserted, the DOM nodes and child component state (typed text, open panels, focus) stay where they were and end up next to the wrong data.
Poprawka
Bind a stable, unique value from the item: :key="item.id". On <template v-for>, put the key on the <template> itself (Vue 3), not on its children.
Przykłady
<!-- bad -->
<li v-for="todo in todos">{{ todo.title }}</li>
<!-- good -->
<li v-for="todo in todos" :key="todo.id">{{ todo.title }}</li>Źródła
Fakty
- Identyfikator
vue/require-v-for-key- Waga
- umiarkowana
- Sprawdzanie
- statyczne sprawdzane w kodzie źródłowym przez
audit - Dotyczy plików
vue- Tylko w projektach z
vuenuxt- Uczy jej skill
fe-vueVue components- Od wersji
- 0.1.0
Przeczytaj w terminalu
npx github:dawidolko/frontend-skills explain vue/require-v-for-key