Browse Source

Allow slot names to be numbers (#5481)

Closes #5480
Eduardo San Martin Morote 9 years ago
parent
commit
380e988823

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

@@ -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)

+ 14 - 0
test/unit/features/component/component-slot.spec.js

@@ -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>'