Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion packages/create-instance/create-functional-component.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import { throwError } from 'shared/util'
import { validateSlots } from './validate-slots'
import { createSlotVNodes } from './create-slot-vnodes'
import createScopedSlots from './create-scoped-slots'

export default function createFunctionalComponent (
component: Component,
Expand All @@ -15,11 +16,15 @@ export default function createFunctionalComponent (
validateSlots(mountingOptions.slots)
}

const data = mountingOptions.context ||
component.FunctionalRenderContext || {}
data.scopedSlots = createScopedSlots(mountingOptions.scopedSlots)

return {
render (h: Function) {
return h(
component,
mountingOptions.context || component.FunctionalRenderContext,
data,
(mountingOptions.context &&
mountingOptions.context.children &&
mountingOptions.context.children.map(
Expand Down
44 changes: 44 additions & 0 deletions test/specs/mounting-options/scopedSlots.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,50 @@ describeWithShallowAndMount('scopedSlots', mountingMethod => {
}
)

itDoNotRunIf(
vueVersion < 2.5,
'mounts component scoped slots in render function which exists in functional component',
() => {
const destructuringWrapper = mountingMethod(
{
functional: true,
render: function (createElement, context) {
return context.data.scopedSlots.default({
index: 1,
item: 'foo'
})
}
},
{
scopedSlots: {
default:
'<template slot-scope="{ index, item }"><p>{{index}},{{item}}</p></template>'
}
}
)
expect(destructuringWrapper.html()).to.equal('<p>1,foo</p>')

const notDestructuringWrapper = mountingMethod(
{
functional: true,
render: function (createElement, context) {
return context.data.scopedSlots.named({
index: 1,
item: 'foo'
})
}
},
{
scopedSlots: {
named:
'<p slot-scope="foo">{{foo.index}},{{foo.item}}</p>'
}
}
)
expect(notDestructuringWrapper.html()).to.equal('<p>1,foo</p>')
}
)

itDoNotRunIf(
vueVersion < 2.5,
'mounts component scoped slots',
Expand Down