[Vuejs]-Accessing v-for dynamically created elements outside of loop

0πŸ‘

βœ…

I would like to access all the items so I can display the quantity of
them all.

That is a data operation, not a DOM operation. You don’t get your data from the DOM. It is in your viewmodel. As you figured out (and noted in your comment), you can make a computed.

0πŸ‘

You need to get access from the parent. You can put the v-for on a template tag, and do your iteration there.

<template v-for="item in cart.items">
  <li >
    <h1>{{ item.product.name }}</h1>
  </li>
  <p>{{ item.product.name }}</p>
</template>

This allows you access to each item. See: Templates and v-for

Leave a comment