Vue: getting started

Lesson 03 · 11 min

Lists, computed, keys

v-for without :key is a trap. Computed is a cached formula, not a method called "at every sneeze".

v-for="item in items" draws a list. Always :key="item.id". Computed: const pricey = computed(() => items.value.filter((i) => i.price > 100)). It recomputes only if its dependencies changed. A method in the template, {{ filter() }}, is called on every render — for a filter that's wasted work.

Sign in to continue

The rest of this lesson opens after sign up

The first lesson of every course is open without an account. To read on, solve the practice and use Ask, create a free account or log in.