File tree Expand file tree Collapse file tree 2 files changed +14
-3
lines changed
test/unit/specs/directives Expand file tree Collapse file tree 2 files changed +14
-3
lines changed Original file line number Diff line number Diff line change @@ -181,7 +181,7 @@ function makePropsLinkFn (props) {
181
181
options = prop . options
182
182
if ( prop . raw === null ) {
183
183
// initialize absent prop
184
- _ . initProp ( vm , prop , getDefault ( options ) )
184
+ _ . initProp ( vm , prop , getDefault ( vm , options ) )
185
185
} else if ( prop . dynamic ) {
186
186
// dynamic prop
187
187
if ( vm . _context ) {
@@ -224,11 +224,12 @@ function makePropsLinkFn (props) {
224
224
/**
225
225
* Get the default value of a prop.
226
226
*
227
+ * @param {Vue } vm
227
228
* @param {Object } options
228
229
* @return {* }
229
230
*/
230
231
231
- function getDefault ( options ) {
232
+ function getDefault ( vm , options ) {
232
233
// no default, return undefined
233
234
if ( ! options . hasOwnProperty ( 'default' ) ) {
234
235
// absent boolean value defaults to false
@@ -247,6 +248,6 @@ function getDefault (options) {
247
248
}
248
249
// call factory function for non-Function types
249
250
return typeof def === 'function' && options . type !== Function
250
- ? def ( )
251
+ ? def . call ( vm )
251
252
: def
252
253
}
Original file line number Diff line number Diff line change @@ -579,6 +579,12 @@ if (_.inBrowser) {
579
579
prop : {
580
580
type : String ,
581
581
default : 'hello'
582
+ } ,
583
+ prop2 : {
584
+ type : Object ,
585
+ default : function ( ) {
586
+ return { vm : this }
587
+ }
582
588
}
583
589
} ,
584
590
data : function ( ) {
@@ -591,6 +597,10 @@ if (_.inBrowser) {
591
597
}
592
598
} )
593
599
expect ( vm . $el . textContent ) . toBe ( 'hello world' )
600
+ // object/array default value initializers should be
601
+ // called with the correct `this` context
602
+ var child = vm . $children [ 0 ]
603
+ expect ( child . prop2 . vm ) . toBe ( child )
594
604
vm . $children [ 0 ] . prop = 'bye'
595
605
_ . nextTick ( function ( ) {
596
606
expect ( vm . $el . textContent ) . toBe ( 'bye world' )
You can’t perform that action at this time.
0 commit comments