@@ -10,7 +10,6 @@ import {
10
10
warn ,
11
11
query ,
12
12
hasOwn ,
13
- set ,
14
13
isReserved ,
15
14
bind
16
15
} from '../../util/index'
@@ -76,41 +75,35 @@ export default function (Vue) {
76
75
*/
77
76
78
77
Vue . prototype . _initData = function ( ) {
79
- var propsData = this . _data
80
- var optionsDataFn = this . $options . data
81
- var optionsData = optionsDataFn && optionsDataFn ( )
82
- var runtimeData
83
- if ( process . env . NODE_ENV !== 'production' ) {
84
- runtimeData = ( typeof this . _runtimeData === 'function'
78
+ var dataFn = this . $options . data
79
+ var data = this . _data = dataFn ? dataFn ( ) : { }
80
+ var props = this . _props
81
+ var runtimeData = this . _runtimeData
82
+ ? typeof this . _runtimeData === 'function'
85
83
? this . _runtimeData ( )
86
- : this . _runtimeData ) || { }
87
- this . _runtimeData = null
88
- }
89
- if ( optionsData ) {
90
- this . _data = optionsData
91
- for ( var prop in propsData ) {
92
- if ( process . env . NODE_ENV !== 'production' &&
93
- hasOwn ( optionsData , prop ) &&
94
- ! hasOwn ( runtimeData , prop ) ) {
95
- warn (
96
- 'Data field "' + prop + '" is already defined ' +
97
- 'as a prop. Use prop default value instead.'
98
- )
99
- }
100
- if ( this . _props [ prop ] . raw !== null ||
101
- ! hasOwn ( optionsData , prop ) ) {
102
- set ( optionsData , prop , propsData [ prop ] )
103
- }
104
- }
105
- }
106
- var data = this . _data
84
+ : this . _runtimeData
85
+ : null
107
86
// proxy data on instance
108
87
var keys = Object . keys ( data )
109
88
var i , key
110
89
i = keys . length
111
90
while ( i -- ) {
112
91
key = keys [ i ]
113
- this . _proxy ( key )
92
+ // there are two scenarios where we can proxy a data key:
93
+ // 1. it's not already defined as a prop
94
+ // 2. it's provided via a instantiation option AND there are no
95
+ // template prop present
96
+ if (
97
+ ! props || ! hasOwn ( props , key ) ||
98
+ ( runtimeData && hasOwn ( runtimeData , key ) && props [ key ] . raw === null )
99
+ ) {
100
+ this . _proxy ( key )
101
+ } else if ( process . env . NODE_ENV !== 'production' ) {
102
+ warn (
103
+ 'Data field "' + key + '" is already defined ' +
104
+ 'as a prop. Use prop default value instead.'
105
+ )
106
+ }
114
107
}
115
108
// observe data
116
109
observe ( data , this )
0 commit comments