Bläddra i källkod

should not skip observation for non-simple-path props (fix #2516)

Evan You 10 år sedan
förälder
incheckning
30e9edaf8e
2 ändrade filer med 22 tillägg och 1 borttagningar
  1. 3 1
      src/compiler/compile-props.js
  2. 19 0
      test/unit/specs/directives/internal/prop_spec.js

+ 3 - 1
src/compiler/compile-props.js

@@ -1,5 +1,6 @@
 import config from '../config'
 import { parseDirective } from '../parsers/directive'
+import { isSimplePath } from '../parsers/expression'
 import { defineReactive } from '../observer/index'
 import propDef from '../directives/internal/prop'
 import {
@@ -221,7 +222,8 @@ export function initProp (vm, prop, value) {
     value = getPropDefaultValue(vm, prop.options)
   }
   if (assertProp(prop, value)) {
-    defineReactive(vm, key, value, true /* doNotObserve */)
+    var doNotObserve = !prop.dynamic || isSimplePath(prop.raw)
+    defineReactive(vm, key, value, doNotObserve)
   }
 }
 

+ 19 - 0
test/unit/specs/directives/internal/prop_spec.js

@@ -700,4 +700,23 @@ describe('prop', function () {
       done()
     })
   })
+
+  it('inline prop values should be converted', function (done) {
+    var vm = new Vue({
+      el: el,
+      template: '<comp :a="[1, 2, 3]"></comp>',
+      components: {
+        comp: {
+          props: ['a'],
+          template: '<div v-for="i in a">{{ i }}</div>'
+        }
+      }
+    })
+    expect(vm.$el.textContent).toBe('123')
+    vm.$children[0].a.pop()
+    Vue.nextTick(function () {
+      expect(vm.$el.textContent).toBe('12')
+      done()
+    })
+  })
 })