[Vuejs]-How to access data returned via method per item in v-for

0đź‘Ť

âś…

There’s no real way to make a “temporary variable” inside a loop, but you can use the fact that v-for makes an alias for what it’s looping over:

<div v-for="deal in deals">
  <div class="card">
    <h3>{{deal.name}}</h3>
    <template v-for="sponsor in [getSponsor(key)]">
      <p>{{ sponsor }}</p>
      <p>{{sponsor.name}}</p>
    </template>
  </div>
</div>

If key is just a prop to component, then you can make a computed based on it:

sponsor() {
  return getSponsor(key);
}

and use it as I used the alias above.

Leave a comment