Forráskód Böngészése

warn v-repeat filters that do not return Arrays

Evan You 10 éve
szülő
commit
39d978d948
2 módosított fájl, 22 hozzáadás és 0 törlés
  1. 6 0
      src/directives/repeat.js
  2. 16 0
      test/unit/specs/directives/repeat_spec.js

+ 6 - 0
src/directives/repeat.js

@@ -192,6 +192,12 @@ module.exports = {
    */
 
   update: function (data) {
+    if (process.env.NODE_ENV !== 'production' && !_.isArray(data)) {
+      _.warn(
+        'v-repeat pre-converts Objects into Arrays, and ' +
+        'v-repeat filters should always return Arrays.'
+      )
+    }
     if (this.componentId) {
       var state = this.componentState
       if (state === UNRESOLVED) {

+ 16 - 0
test/unit/specs/directives/repeat_spec.js

@@ -802,6 +802,22 @@ if (_.inBrowser) {
       })
     })
 
+    it('warn filters that return non-Array values', function () {
+      new Vue({
+        el: el,
+        template: '<div v-repeat="items | test"></div>',
+        data: {
+          items: []
+        },
+        filters: {
+          test: function (val) {
+            return {}
+          }
+        }
+      })
+      expect(hasWarned(_, 'should always return Arrays')).toBe(true)
+    })
+
   })
 }