Преглед изворни кода

fix: new syntax slots without scope should also be exposed on functional slots()

Evan You пре 7 година
родитељ
комит
8a800867fe

+ 9 - 1
src/core/vdom/create-functional-component.js

@@ -49,7 +49,15 @@ export function FunctionalRenderContext (
   this.parent = parent
   this.listeners = data.on || emptyObject
   this.injections = resolveInject(options.inject, parent)
-  this.slots = () => this.$slots || (this.$slots = resolveSlots(children, parent))
+  this.slots = () => {
+    if (!this.$slots) {
+      normalizeScopedSlots(
+        data.scopedSlots,
+        this.$slots = resolveSlots(children, parent)
+      )
+    }
+    return this.$slots
+  }
 
   Object.defineProperty(this, 'scopedSlots', ({
     enumerable: true,

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

@@ -1088,4 +1088,19 @@ describe('Component scoped slot', () => {
     }).$mount()
     expect(vm.$el.textContent).toBe('')
   })
+
+  it('should expose v-slot without scope on ctx.slots() in functional', () => {
+    const vm = new Vue({
+      template: `<foo><template v-slot>hello</template></foo>`,
+      components: {
+        foo: {
+          functional: true,
+          render(h, ctx) {
+            return h('div', ctx.slots().default)
+          }
+        }
+      }
+    }).$mount()
+    expect(vm.$el.textContent).toBe('hello')
+  })
 })