Skip to content

Commit 96a09aa

Browse files
committedFeb 6, 2019
fix(compiler): fix v-bind dynamic arguments on slot outlets
fix #9444
1 parent 4d4d22a commit 96a09aa

File tree

2 files changed

+33
-1
lines changed

2 files changed

+33
-1
lines changed
 

‎src/compiler/codegen/index.js

+8-1
Original file line numberDiff line numberDiff line change
@@ -501,7 +501,14 @@ function genSlot (el: ASTElement, state: CodegenState): string {
501501
const slotName = el.slotName || '"default"'
502502
const children = genChildren(el, state)
503503
let res = `_t(${slotName}${children ? `,${children}` : ''}`
504-
const attrs = el.attrs && `{${el.attrs.map(a => `${camelize(a.name)}:${a.value}`).join(',')}}`
504+
const attrs = el.attrs || el.dynamicAttrs
505+
? genProps((el.attrs || []).concat(el.dynamicAttrs || []).map(attr => ({
506+
// slot props are camelized
507+
name: camelize(attr.name),
508+
value: attr.value,
509+
dynamic: attr.dynamic
510+
})))
511+
: null
505512
const bind = el.attrsMap['v-bind']
506513
if ((attrs || bind) && !children) {
507514
res += `,null`

‎test/unit/features/component/component-scoped-slot.spec.js

+25
Original file line numberDiff line numberDiff line change
@@ -1027,4 +1027,29 @@ describe('Component scoped slot', () => {
10271027
expect(vm.$el.textContent).toBe(`2`)
10281028
}).then(done)
10291029
})
1030+
1031+
it('dynamic v-bind arguments on <slot>', done => {
1032+
const Foo = {
1033+
data() {
1034+
return {
1035+
key: 'msg'
1036+
}
1037+
},
1038+
template: `<div><slot :[key]="'hello'"/></div>`
1039+
}
1040+
1041+
const vm = new Vue({
1042+
components: { Foo },
1043+
template: `
1044+
<foo ref="foo" v-slot="props">{{ props }}</foo>
1045+
`
1046+
}).$mount()
1047+
1048+
expect(vm.$el.textContent).toBe(JSON.stringify({ msg: 'hello' }, null, 2))
1049+
1050+
vm.$refs.foo.key = 'changed'
1051+
waitForUpdate(() => {
1052+
expect(vm.$el.textContent).toBe(JSON.stringify({ changed: 'hello' }, null, 2))
1053+
}).then(done)
1054+
})
10301055
})

0 commit comments

Comments
 (0)
Please sign in to comment.