Skip to content

Commit eda37b9

Browse files
committed
warn v-for filters that do not return Arrays
1 parent f38d685 commit eda37b9

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

src/directives/for.js

+6
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,12 @@ module.exports = {
7070
},
7171

7272
update: function (data) {
73+
if (process.env.NODE_ENV !== 'production' && !_.isArray(data)) {
74+
_.warn(
75+
'v-for pre-converts Objects into Arrays, and ' +
76+
'v-for filters should always return Arrays.'
77+
)
78+
}
7379
this.diff(data)
7480
this.updateRef()
7581
this.updateModel()

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

+16
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)