Vue
vue/no-v-if-with-v-for
Never put v-if and v-for on the same element; filter in a computed list or move v-if to a wrapper.
umiarkowanastatycznefe-vue
Dlaczego
In Vue 3, v-if is evaluated before v-for on the same element, so the condition cannot see the loop variable: v-for="user in users" v-if="user.active" throws or hides the whole list. In Vue 2 the order was the reverse, which is why old code and old answers still show this pattern.
Poprawka
Filter in a computed property and loop over it (v-for="user in activeUsers"). To hide the whole list, put v-if on a wrapper element or a <template> around the loop.
Przykłady
<!-- bad -->
<li v-for="user in users" v-if="user.active" :key="user.id">{{ user.name }}</li>
<!-- good -->
<li v-for="user in activeUsers" :key="user.id">{{ user.name }}</li>Źródła
Fakty
- Identyfikator
vue/no-v-if-with-v-for- 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/no-v-if-with-v-for