Skip to content

feat(core): support passing down scopedSlots with v-bind #7765

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/core/instance/render-helpers/bind-object-props.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ export function bindObjectProps (
if (
key === 'class' ||
key === 'style' ||
key === 'scopedSlots' ||
isReservedAttribute(key)
) {
hash = data
Expand Down
103 changes: 103 additions & 0 deletions test/unit/features/component/component-scoped-slot.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -593,4 +593,107 @@ describe('Component scoped slot', () => {
expect(vm.$el.innerHTML).toBe('<p>hello</p>')
}).then(done)
})

it('passing down scoped slots with v-bind', () => {
const Bar = {
template: `
<div class="bar">
<slot name="hello" msg="hi" />
</div>
`
}

const Foo = {
components: { Bar },
template: `
<div class="foo">
<bar v-bind="{ scopedSlots: $scopedSlots }"></bar>
</div>
`
}

const vm = new Vue({
components: { Foo },
template: `
<foo>
<template slot="hello" slot-scope="props">
{{ props.msg + '!' }}
</template>
</foo>
`
}).$mount()

expect(vm.$el.querySelector('.bar').textContent.trim()).toBe('hi!')
})

it('passing down merged scoped slots with v-bind', () => {
const Bar = {
template: `
<div class="bar">
<slot name="one" msg="1" />
<slot name="two" msg="2" />
</div>
`
}

const Ney = {
template: `
<div class="ney">
<slot name="three" msg="3">
3?
</slot>
</div>
`
}

const Foo = {
components: { Bar, Ney },
template: `
<div class="foo">
<bar v-bind="{ scopedSlots: $scopedSlots }"></bar>
<ney v-bind="{ scopedSlots: $scopedSlots }"></ney>
</div>
`
}

const vm1 = new Vue({
components: { Foo },
template: `
<foo>
<template slot="one" slot-scope="props">
{{ props.msg + '!' }}
</template>
<template slot="two" slot-scope="props">
{{ props.msg + '!!' }}
</template>
</foo>
`
}).$mount()

expect(vm1.$el.textContent.trim().replace(/\s+/g, '')).toBe('1!2!!3?')

const vm2 = new Vue({
components: { Foo },
methods: {
tickle (me) {
return me + ' tickled!'
}
},
template: `
<foo>
<template slot="one" slot-scope="props">
{{ props.msg + '!' }}
</template>
<template slot="two" slot-scope="props">
{{ props.msg + '!!' }}
</template>
<template slot="three" slot-scope="props">
{{ tickle( props.msg )}}
</template>
</foo>
`
}).$mount()

expect(vm2.$el.textContent.trim().replace(/\s+/g, '')).toBe('1!2!!3tickled!')
})
})