File tree 3 files changed +55
-9
lines changed
test/unit/features/component
3 files changed +55
-9
lines changed Original file line number Diff line number Diff line change @@ -343,13 +343,19 @@ function genText (text: ASTText | ASTExpression): string {
343
343
function genSlot ( el : ASTElement ) : string {
344
344
const slotName = el . slotName || '"default"'
345
345
const children = genChildren ( el )
346
- return `_t(${ slotName } ${
347
- children ? `,${ children } ` : ''
348
- } ${
349
- el . attrs ? `${ children ? '' : ',null' } ,{${
350
- el . attrs . map ( a => `${ camelize ( a . name ) } :${ a . value } ` ) . join ( ',' )
351
- } }` : ''
352
- } )`
346
+ let res = `_t(${ slotName } ${ children ? `,${ children } ` : '' } `
347
+ const attrs = el . attrs && `{${ el . attrs . map ( a => `${ camelize ( a . name ) } :${ a . value } ` ) . join ( ',' ) } }`
348
+ const bind = el . attrsMap [ 'v-bind' ]
349
+ if ( ( attrs || bind ) && ! children ) {
350
+ res += `,null`
351
+ }
352
+ if ( attrs ) {
353
+ res += `,${ attrs } `
354
+ }
355
+ if ( bind ) {
356
+ res += `${ attrs ? '' : ',null' } ,${ bind } `
357
+ }
358
+ return res + ')'
353
359
}
354
360
355
361
// componentName is el.component, take it as argument to shun flow's pessimistic refinement
Original file line number Diff line number Diff line change @@ -9,6 +9,7 @@ import VNode, {
9
9
} from '../vdom/vnode'
10
10
import {
11
11
warn ,
12
+ extend ,
12
13
identity ,
13
14
isObject ,
14
15
toObject ,
@@ -203,11 +204,16 @@ export function renderMixin (Vue: Class<Component>) {
203
204
Vue . prototype . _t = function (
204
205
name : string ,
205
206
fallback : ?Array < VNode > ,
206
- props : ?Object
207
+ props : ?Object ,
208
+ bindObject : ?Object
207
209
) : ?Array < VNode > {
208
210
const scopedSlotFn = this . $scopedSlots [ name ]
209
211
if ( scopedSlotFn ) { // scoped slot
210
- return scopedSlotFn ( props || { } ) || fallback
212
+ props = props || { }
213
+ if ( bindObject ) {
214
+ extend ( props , bindObject )
215
+ }
216
+ return scopedSlotFn ( props ) || fallback
211
217
} else {
212
218
const slotNodes = this . $slots [ name ]
213
219
// warn duplicate slot usage
Original file line number Diff line number Diff line change @@ -31,6 +31,40 @@ describe('Component scoped slot', () => {
31
31
} ) . then ( done )
32
32
} )
33
33
34
+ it ( 'with v-bind' , done => {
35
+ const vm = new Vue ( {
36
+ template : `
37
+ <test ref="test">
38
+ <template scope="props">
39
+ <span>{{ props.msg }} {{ props.msg2 }}</span>
40
+ </template>
41
+ </test>
42
+ ` ,
43
+ components : {
44
+ test : {
45
+ data ( ) {
46
+ return {
47
+ msg : 'hello' ,
48
+ obj : { msg2 : 'world' }
49
+ }
50
+ } ,
51
+ template : `
52
+ <div>
53
+ <slot :msg="msg" v-bind="obj"></slot>
54
+ </div>
55
+ `
56
+ }
57
+ }
58
+ } ) . $mount ( )
59
+
60
+ expect ( vm . $el . innerHTML ) . toBe ( '<span>hello world</span>' )
61
+ vm . $refs . test . msg = 'bye'
62
+ vm . $refs . test . obj . msg2 = 'bye'
63
+ waitForUpdate ( ( ) => {
64
+ expect ( vm . $el . innerHTML ) . toBe ( '<span>bye bye</span>' )
65
+ } ) . then ( done )
66
+ } )
67
+
34
68
it ( 'template slot' , done => {
35
69
const vm = new Vue ( {
36
70
template : `
You can’t perform that action at this time.
0 commit comments