Skip to content

Commit

Permalink
Allow slot names to be numbers (#5481)
Browse files Browse the repository at this point in the history
Closes #5480
  • Loading branch information
posva authored and yyx990803 committed Apr 25, 2017
1 parent 1288386 commit 380e988
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/core/instance/render-helpers/resolve-slots.js
Expand Up @@ -18,7 +18,7 @@ export function resolveSlots (
// named slots should only be respected if the vnode was rendered in the
// same context.
if ((child.context === context || child.functionalContext === context) &&
child.data && (name = child.data.slot)) {
child.data && (name = child.data.slot) != null) {
const slot = (slots[name] || (slots[name] = []))
if (child.tag === 'template') {
slot.push.apply(slot, child.children)
Expand Down
14 changes: 14 additions & 0 deletions test/unit/features/component/component-slot.spec.js
Expand Up @@ -57,6 +57,20 @@ describe('Component slot', () => {
}).then(done)
})

it('named slot with 0 as a number', done => {
mount({
childTemplate: '<div><slot :name="0"></slot></div>',
parentContent: '<p :slot="0">{{ msg }}</p>'
})
expect(child.$el.tagName).toBe('DIV')
expect(child.$el.children[0].tagName).toBe('P')
expect(child.$el.children[0].textContent).toBe('parent message')
vm.msg = 'changed'
waitForUpdate(() => {
expect(child.$el.children[0].textContent).toBe('changed')
}).then(done)
})

it('fallback content', () => {
mount({
childTemplate: '<div><slot><p>{{msg}}</p></slot></div>'
Expand Down

0 comments on commit 380e988

Please sign in to comment.