Skip to content

Commit fb6aa06

Browse files
posvayyx990803
authored andcommitted
feat(functional): add scopedSlots to context in functional components (#7941)
1 parent 5d52262 commit fb6aa06

File tree

4 files changed

+21
-1
lines changed

4 files changed

+21
-1
lines changed

src/core/vdom/create-functional-component.js

+1
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ export function FunctionalRenderContext (
4848
this.children = children
4949
this.parent = parent
5050
this.listeners = data.on || emptyObject
51+
this.scopedSlots = data.scopedSlots || emptyObject
5152
this.injections = resolveInject(options.inject, parent)
5253
this.slots = () => resolveSlots(children, parent)
5354

test/unit/features/options/functional.spec.js

+17
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,23 @@ describe('Options functional', () => {
7979
document.body.removeChild(vm.$el)
8080
})
8181

82+
it('should expose data.scopedSlots as scopedSlots', () => {
83+
const vm = new Vue({
84+
template: '<div><wrap><p slot-scope="a">{{ a }}</p></wrap></div>',
85+
components: {
86+
wrap: {
87+
functional: true,
88+
render (h, { scopedSlots, data }) {
89+
expect(data.scopedSlots).toBe(scopedSlots)
90+
return data.scopedSlots.default('a')
91+
}
92+
}
93+
}
94+
}).$mount()
95+
96+
expect(vm.$el.textContent).toBe('a')
97+
})
98+
8299
it('should support returning more than one root node', () => {
83100
const vm = new Vue({
84101
template: `<div><test></test></div>`,

types/options.d.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { Vue, CreateElement, CombinedVueInstance } from "./vue";
2-
import { VNode, VNodeData, VNodeDirective } from "./vnode";
2+
import { VNode, VNodeData, VNodeDirective, ScopedSlot } from "./vnode";
33

44
type Constructor = {
55
new (...args: any[]): any;
@@ -140,6 +140,7 @@ export interface RenderContext<Props=DefaultProps> {
140140
data: VNodeData;
141141
parent: Vue;
142142
listeners: { [key: string]: Function | Function[] };
143+
scopedSlots: { [key: string]: ScopedSlot };
143144
injections: any
144145
}
145146

types/test/options-test.ts

+1
Original file line numberDiff line numberDiff line change
@@ -381,6 +381,7 @@ Vue.component('functional-component', {
381381
context.slots();
382382
context.data;
383383
context.parent;
384+
context.scopedSlots;
384385
context.listeners.click;
385386
return createElement("div", {}, context.children);
386387
}

0 commit comments

Comments
 (0)