Vue: Question: How to iterate over maps and sets with v-for

Created on 19 Sep 2017  路  6Comments  路  Source: vuejs/vue

What problem does this feature solve?

How to iterate over Map and Set with v-for ? I want to use the key/index field or both.(ES6 Map/Set)

<mt-index-list>
  <mt-index-section v-for="(list, key) in serverData.indexMap" :index="key" :key="key">
    <mt-cell title="Aaron"></mt-cell>
  </mt-index-section>
</mt-index-list>

What does the proposed API look like?

N/A

Most helpful comment

It's currently not supported in core (there's no reactivity detection for these data structures). But you can use (list, key) in Array.from(map) + $forceUpdate() to simulate it.

All 6 comments

Maps and sets are not currently supported in v-for, heard it will be possible in Vue 3.0

It's currently not supported in core (there's no reactivity detection for these data structures). But you can use (list, key) in Array.from(map) + $forceUpdate() to simulate it.

@yyx990803 @sqal
OK, I got it. Thanks for your reply.

Thanks

For those coming from google, this is not supported, nor is it planned to be.

Please see this issue: https://github.com/vuejs/vue/issues/2410

if not v-for then is there any other way to iterate over map in vuejs?

Was this page helpful?
0 / 5 - 0 ratings