File tree Expand file tree Collapse file tree 2 files changed +14
-3
lines changed
test/unit/specs/directives/internal Expand file tree Collapse file tree 2 files changed +14
-3
lines changed Original file line number Diff line number Diff line change @@ -131,7 +131,7 @@ function makePropsLinkFn (props) {
131
131
vm . _props [ path ] = prop
132
132
if ( raw === null ) {
133
133
// initialize absent prop
134
- _ . initProp ( vm , prop , getDefault ( options ) )
134
+ _ . initProp ( vm , prop , getDefault ( vm , options ) )
135
135
} else if ( prop . dynamic ) {
136
136
// dynamic prop
137
137
if ( vm . _context ) {
@@ -174,11 +174,12 @@ function makePropsLinkFn (props) {
174
174
/**
175
175
* Get the default value of a prop.
176
176
*
177
+ * @param {Vue } vm
177
178
* @param {Object } options
178
179
* @return {* }
179
180
*/
180
181
181
- function getDefault ( options ) {
182
+ function getDefault ( vm , options ) {
182
183
// no default, return undefined
183
184
if ( ! options . hasOwnProperty ( 'default' ) ) {
184
185
// absent boolean value defaults to false
@@ -197,6 +198,6 @@ function getDefault (options) {
197
198
}
198
199
// call factory function for non-Function types
199
200
return typeof def === 'function' && options . type !== Function
200
- ? def ( )
201
+ ? def . call ( vm )
201
202
: def
202
203
}
Original file line number Diff line number Diff line change @@ -496,6 +496,12 @@ if (_.inBrowser) {
496
496
prop : {
497
497
type : String ,
498
498
default : 'hello'
499
+ } ,
500
+ prop2 : {
501
+ type : Object ,
502
+ default : function ( ) {
503
+ return { vm : this }
504
+ }
499
505
}
500
506
} ,
501
507
data : function ( ) {
@@ -508,6 +514,10 @@ if (_.inBrowser) {
508
514
}
509
515
} )
510
516
expect ( vm . $el . textContent ) . toBe ( 'hello world' )
517
+ // object/array default value initializers should be
518
+ // called with the correct `this` context
519
+ var child = vm . $children [ 0 ]
520
+ expect ( child . prop2 . vm ) . toBe ( child )
511
521
vm . $children [ 0 ] . prop = 'bye'
512
522
_ . nextTick ( function ( ) {
513
523
expect ( vm . $el . textContent ) . toBe ( 'bye world' )
You can’t perform that action at this time.
0 commit comments