Skip to content

Commit 00568ce

Browse files
committed
warn v-for filters that do not return Arrays
1 parent 70944fb commit 00568ce

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

src/directives/public/for.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,12 @@ module.exports = {
6161
},
6262

6363
update: function (data) {
64+
if (process.env.NODE_ENV !== 'production' && !_.isArray(data)) {
65+
_.warn(
66+
'v-for pre-converts Objects into Arrays, and ' +
67+
'v-for filters should always return Arrays.'
68+
)
69+
}
6470
this.diff(data)
6571
this.updateRef()
6672
this.updateModel()

test/unit/specs/directives/public/for/for_spec.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -660,6 +660,22 @@ if (_.inBrowser) {
660660
expect(hasWarned(_, 'It seems you are using two-way binding')).toBe(true)
661661
})
662662

663+
it('warn filters that return non-Array values', function () {
664+
new Vue({
665+
el: el,
666+
template: '<div v-for="item in items | test"></div>',
667+
data: {
668+
items: []
669+
},
670+
filters: {
671+
test: function (val) {
672+
return {}
673+
}
674+
}
675+
})
676+
expect(hasWarned(_, 'should always return Arrays')).toBe(true)
677+
})
678+
663679
it('nested track by', function (done) {
664680
var vm = new Vue({
665681
el: el,

0 commit comments

Comments
 (0)