Skip to content

Commit 380e988

Browse files
posvayyx990803
authored andcommitted
Allow slot names to be numbers (vuejs#5481)
Closes vuejs#5480
1 parent 1288386 commit 380e988

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

src/core/instance/render-helpers/resolve-slots.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ export function resolveSlots (
1818
// named slots should only be respected if the vnode was rendered in the
1919
// same context.
2020
if ((child.context === context || child.functionalContext === context) &&
21-
child.data && (name = child.data.slot)) {
21+
child.data && (name = child.data.slot) != null) {
2222
const slot = (slots[name] || (slots[name] = []))
2323
if (child.tag === 'template') {
2424
slot.push.apply(slot, child.children)

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,20 @@ describe('Component slot', () => {
5757
}).then(done)
5858
})
5959

60+
it('named slot with 0 as a number', done => {
61+
mount({
62+
childTemplate: '<div><slot :name="0"></slot></div>',
63+
parentContent: '<p :slot="0">{{ msg }}</p>'
64+
})
65+
expect(child.$el.tagName).toBe('DIV')
66+
expect(child.$el.children[0].tagName).toBe('P')
67+
expect(child.$el.children[0].textContent).toBe('parent message')
68+
vm.msg = 'changed'
69+
waitForUpdate(() => {
70+
expect(child.$el.children[0].textContent).toBe('changed')
71+
}).then(done)
72+
})
73+
6074
it('fallback content', () => {
6175
mount({
6276
childTemplate: '<div><slot><p>{{msg}}</p></slot></div>'

0 commit comments

Comments
 (0)