Vue: v-for should iterate object iterator (if one exists)

Created on 2 Jul 2018  路  2Comments  路  Source: vuejs/vue

What problem does this feature solve?

Please see here:
https://jsfiddle.net/tys426eq/

If a class has its own iterator, v-for should iterate over this, instead of the object properties

What does the proposed API look like?

class Items {
  [Symbol.iterator]() {
    return this.all.values();
  }
}

...
<div v-for="item of items"> (or "in")

feature request has PR

Most helpful comment

If I recall correctly this is planned for v3 and may be added in v2
Other issues #5893, #6079
PR: https://github.com/vuejs/vue/pull/7171, https://github.com/vuejs/vue/pull/8179

All 2 comments

If I recall correctly this is planned for v3 and may be added in v2
Other issues #5893, #6079
PR: https://github.com/vuejs/vue/pull/7171, https://github.com/vuejs/vue/pull/8179

This is working since vue 2.6.x

core/v-for: support iterables in v-for (#8179) d40eb9c, closes #8179

Was this page helpful?
0 / 5 - 0 ratings