Skip to content

Commit

Permalink
fix(compiler): fix v-bind dynamic arguments on slot outlets
Browse files Browse the repository at this point in the history
fix #9444
  • Loading branch information
yyx990803 committed Feb 6, 2019
1 parent 4d4d22a commit 96a09aa
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/compiler/codegen/index.js
Expand Up @@ -501,7 +501,14 @@ function genSlot (el: ASTElement, state: CodegenState): string {
const slotName = el.slotName || '"default"'
const children = genChildren(el, state)
let res = `_t(${slotName}${children ? `,${children}` : ''}`
const attrs = el.attrs && `{${el.attrs.map(a => `${camelize(a.name)}:${a.value}`).join(',')}}`
const attrs = el.attrs || el.dynamicAttrs
? genProps((el.attrs || []).concat(el.dynamicAttrs || []).map(attr => ({
// slot props are camelized
name: camelize(attr.name),
value: attr.value,
dynamic: attr.dynamic
})))
: null
const bind = el.attrsMap['v-bind']
if ((attrs || bind) && !children) {
res += `,null`
Expand Down
25 changes: 25 additions & 0 deletions test/unit/features/component/component-scoped-slot.spec.js
Expand Up @@ -1027,4 +1027,29 @@ describe('Component scoped slot', () => {
expect(vm.$el.textContent).toBe(`2`)
}).then(done)
})

it('dynamic v-bind arguments on <slot>', done => {
const Foo = {
data() {
return {
key: 'msg'
}
},
template: `<div><slot :[key]="'hello'"/></div>`
}

const vm = new Vue({
components: { Foo },
template: `
<foo ref="foo" v-slot="props">{{ props }}</foo>
`
}).$mount()

expect(vm.$el.textContent).toBe(JSON.stringify({ msg: 'hello' }, null, 2))

vm.$refs.foo.key = 'changed'
waitForUpdate(() => {
expect(vm.$el.textContent).toBe(JSON.stringify({ changed: 'hello' }, null, 2))
}).then(done)
})
})

0 comments on commit 96a09aa

Please sign in to comment.