Selaa lähdekoodia

fix slot resolved incorrect with abstract component (fix #5888) (#5895)

kingwl 9 vuotta sitten
vanhempi
commit
213f136a6e

+ 7 - 1
src/core/vdom/create-component.js

@@ -169,8 +169,14 @@ export function createComponent (
 
   if (isTrue(Ctor.options.abstract)) {
     // abstract components do not keep anything
-    // other than props & listeners
+    // other than props & listeners & slot
+
+    // work around flow
+    const slot = data.slot
     data = {}
+    if (slot) {
+      data.slot = slot
+    }
   }
 
   // merge component management hooks onto the placeholder node

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

@@ -660,4 +660,29 @@ describe('Component slot', () => {
       expect(vm.$el.querySelector('input').value).toBe('b')
     }).then(done)
   })
+
+  // Github issue #5888
+  it('should resolve correctly slot with keep-alive', () => {
+    const vm = new Vue({
+      template: `
+      <div>
+        <container>
+          <keep-alive slot="foo">
+            <child></child>
+          </keep-alive>
+        </container>
+      </div>
+      `,
+      components: {
+        container: {
+          template:
+            '<div><slot>default</slot><slot name="foo">named</slot></div>'
+        },
+        child: {
+          template: '<span>foo</span>'
+        }
+      }
+    }).$mount()
+    expect(vm.$el.innerHTML).toBe('<div>default<span>foo</span></div>')
+  })
 })