File tree Expand file tree Collapse file tree 3 files changed +38
-3
lines changed
test/unit/specs/directives/internal Expand file tree Collapse file tree 3 files changed +38
-3
lines changed Original file line number Diff line number Diff line change @@ -81,6 +81,13 @@ export default function (Vue) {
81
81
this . $parent . $children . push ( this )
82
82
}
83
83
84
+ // save raw constructor data before merge
85
+ // so that we know which properties are provided at
86
+ // instantiation.
87
+ if ( process . env . NODE_ENV !== 'production' ) {
88
+ this . _runtimeData = options . data
89
+ }
90
+
84
91
// merge options.
85
92
options = this . $options = mergeOptions (
86
93
this . constructor . options ,
Original file line number Diff line number Diff line change @@ -80,11 +80,19 @@ export default function (Vue) {
80
80
var propsData = this . _data
81
81
var optionsDataFn = this . $options . data
82
82
var optionsData = optionsDataFn && optionsDataFn ( )
83
+ var runtimeData
84
+ if ( process . env . NODE_ENV !== 'production' ) {
85
+ runtimeData = ( typeof this . _runtimeData === 'function'
86
+ ? this . _runtimeData ( )
87
+ : this . _runtimeData ) || { }
88
+ this . _runtimeData = null
89
+ }
83
90
if ( optionsData ) {
84
91
this . _data = optionsData
85
92
for ( var prop in propsData ) {
86
93
if ( process . env . NODE_ENV !== 'production' &&
87
- hasOwn ( optionsData , prop ) ) {
94
+ hasOwn ( optionsData , prop ) &&
95
+ ! hasOwn ( runtimeData , prop ) ) {
88
96
warn (
89
97
'Data field "' + prop + '" is already defined ' +
90
98
'as a prop. Use prop default value instead.'
Original file line number Diff line number Diff line change @@ -562,16 +562,36 @@ describe('prop', function () {
562
562
} )
563
563
564
564
it ( 'should warn data fields already defined as a prop' , function ( ) {
565
+ var Comp = Vue . extend ( {
566
+ data : function ( ) {
567
+ return { a : 123 }
568
+ } ,
569
+ props : {
570
+ a : null
571
+ }
572
+ } )
565
573
new Vue ( {
574
+ el : el ,
575
+ template : '<comp a="1"></comp>' ,
576
+ components : {
577
+ comp : Comp
578
+ }
579
+ } )
580
+ expect ( hasWarned ( 'already defined as a prop' ) ) . toBe ( true )
581
+ } )
582
+
583
+ it ( 'should not warn data fields already defined as a prop if it is from instantiation call' , function ( ) {
584
+ var vm = new Vue ( {
566
585
el : el ,
567
586
props : {
568
587
a : null
569
588
} ,
570
589
data : {
571
- a : 1
590
+ a : 123
572
591
}
573
592
} )
574
- expect ( hasWarned ( 'already defined as a prop' ) ) . toBe ( true )
593
+ expect ( getWarnCount ( ) ) . toBe ( 0 )
594
+ expect ( vm . a ) . toBe ( 123 )
575
595
} )
576
596
577
597
it ( 'should not warn for non-required, absent prop' , function ( ) {
You can’t perform that action at this time.
0 commit comments