Vue Performance
#
v-for with Ionic ComponentsWhen using v-for
with Ionic components, we recommend using Vue's key
attribute. This allows Vue to re-render loop elements in an efficient way by only updating the content inside of the component rather than re-creating the component altogether.
By using key
you can provide a stable identity for each loop element so Vue can track insertions and deletions within the iterator. Below is an example of how to use key
:
In this example, we have an array of objects called items
. Each object contains a value
and an id
. Using the key
attribute, we pass the item.id
for each object. This id
is used to provide a stable identity for each loop element.
For more information on how Vue manages state with v-for
see https://v3.vuejs.org/guide/list.html#maintaining-state