Evan You 10 лет назад
Родитель
Сommit
9f6c23f8c4

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

@@ -163,6 +163,7 @@ function makePropsLinkFn (props) {
   return function propsLinkFn (vm, scope) {
     // store resolved props info
     vm._props = {}
+    var inlineProps = vm.$options.propsData
     var i = props.length
     var prop, path, options, value, raw
     while (i--) {
@@ -171,7 +172,9 @@ function makePropsLinkFn (props) {
       path = prop.path
       options = prop.options
       vm._props[path] = prop
-      if (raw === null) {
+      if (inlineProps && hasOwn(inlineProps, path)) {
+        initProp(vm, prop, inlineProps[path])
+      } if (raw === null) {
         // initialize absent prop
         initProp(vm, prop, undefined)
       } else if (prop.dynamic) {

+ 4 - 5
src/instance/internal/state.js

@@ -97,15 +97,14 @@ export default function (Vue) {
       // 1. it's not already defined as a prop
       // 2. it's provided via a instantiation option AND there are no
       //    template prop present
-      if (
-        !props || !hasOwn(props, key) ||
-        (data && hasOwn(data, key) && props[key].raw === null)
-      ) {
+      if (!props || !hasOwn(props, key)) {
         this._proxy(key)
       } else if (process.env.NODE_ENV !== 'production') {
         warn(
           'Data field "' + key + '" is already defined ' +
-          'as a prop. Use prop default value instead.',
+          'as a prop. To provide default value for a prop, use the "default" ' +
+          'prop option; if you want to pass prop values to an instantiation ' +
+          'call, use the "propsData" option.',
           this
         )
       }

+ 1 - 0
test/unit/specs/compiler/compile_spec.js

@@ -16,6 +16,7 @@ describe('Compile', function () {
     directiveBind = jasmine.createSpy('bind')
     directiveTeardown = jasmine.createSpy('teardown')
     vm = {
+      $options: {},
       _data: {},
       _directives: [],
       _bindDir: function (descriptor, node) {

+ 2 - 2
test/unit/specs/directives/internal/prop_spec.js

@@ -601,13 +601,13 @@ describe('prop', function () {
     expect('already defined as a prop').toHaveBeenWarned()
   })
 
-  it('should not warn data fields already defined as a prop if it is from instantiation call', function () {
+  it('propsData options', function () {
     var vm = new Vue({
       el: el,
       props: {
         a: null
       },
-      data: {
+      propsData: {
         a: 123
       }
     })

+ 0 - 11
test/unit/specs/instance/state_spec.js

@@ -66,17 +66,6 @@ describe('Instance state initialization', function () {
       expect(_.hasOwn(vm, 'c')).toBe(true)
     })
 
-    it('should use default prop value if prop not provided', function () {
-      var vm = new Vue({
-        el: document.createElement('div'),
-        props: ['c'],
-        data: {
-          c: 1
-        }
-      })
-      expect(vm.c).toBe(1)
-    })
-
     it('external prop should overwrite default value', function () {
       var el = document.createElement('div')
       el.setAttribute('v-bind:c', '2')