Просмотр исходного кода

Fixed bug when calling defineReactive on non-existent field with convertAllProperties on

Justin Berger 10 лет назад
Родитель
Сommit
00d11a9e0e
2 измененных файлов с 16 добавлено и 2 удалено
  1. 2 2
      src/observer/index.js
  2. 14 0
      test/unit/specs/directives/public/for/for_spec.js

+ 2 - 2
src/observer/index.js

@@ -181,8 +181,8 @@ function defineReactive (obj, key, val) {
     if (property && property.configurable === false) {
       return
     }
-    getter = property.get
-    setter = property.set
+    getter = property && property.get
+    setter = property && property.set
   }
 
   var childOb = Observer.create(val)

+ 14 - 0
test/unit/specs/directives/public/for/for_spec.js

@@ -1,5 +1,6 @@
 var _ = require('../../../../../../src/util')
 var Vue = require('../../../../../../src/vue')
+var config = require('../../../../../../src/config')
 
 if (_.inBrowser) {
   describe('v-for', function () {
@@ -8,6 +9,7 @@ if (_.inBrowser) {
     beforeEach(function () {
       el = document.createElement('div')
       spyOn(_, 'warn')
+      config.convertAllProperties = false
     })
 
     it('objects', function (done) {
@@ -21,6 +23,18 @@ if (_.inBrowser) {
       assertMutations(vm, el, done)
     })
 
+    it('objects with convertAllProperties on', function (done) {
+      config.convertAllProperties = true
+      var vm = new Vue({
+        el: el,
+        data: {
+          items: [{a: 1}, {a: 2}]
+        },
+        template: '<div v-for="item in items">{{$index}} {{item.a}}</div>'
+      })
+      assertMutations(vm, el, done)
+    })
+
     it('primitives', function (done) {
       var vm = new Vue({
         el: el,