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

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/compiler/codegen/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -546,7 +546,7 @@ export function genComment (comment: ASTText): string {
function genSlot (el: ASTElement, state: CodegenState): string {
const slotName = el.slotName || '"default"'
const children = genChildren(el, state)
let res = `_t(${slotName}${children ? `,${children}` : ''}`
let res = `_t(${slotName}${children ? `,function(){return ${children}}` : ''}`
const attrs = el.attrs || el.dynamicAttrs
? genProps((el.attrs || []).concat(el.dynamicAttrs || []).map(attr => ({
// slot props are camelized
Expand Down
6 changes: 3 additions & 3 deletions src/core/instance/render-helpers/render-slot.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { extend, warn, isObject } from 'core/util/index'
*/
export function renderSlot (
name: string,
fallback: ?Array<VNode>,
fallbackRender: ?() => Array<VNode>,
props: ?Object,
bindObject: ?Object
): ?Array<VNode> {
Expand All @@ -24,9 +24,9 @@ export function renderSlot (
}
props = extend(extend({}, bindObject), props)
}
nodes = scopedSlotFn(props) || fallback
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need to account for already render vnodes here (from component compiled with an older version of Vue)

nodes = scopedSlotFn(props) || (fallbackRender && fallbackRender())
} else {
nodes = this.$slots[name] || fallback
nodes = this.$slots[name] || (fallbackRender && fallbackRender())
}

const target = props && props.slot
Expand Down
20 changes: 20 additions & 0 deletions test/unit/features/component/component-slot.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,26 @@ describe('Component slot', () => {
expect(child.$el.children[1].textContent).toBe('slot b')
})

it('fallback content should not be evaluated when the parent is providing it', () => {
const test = jasmine.createSpy('test')
const vm = new Vue({
template: '<test>slot default</test>',
components: {
test: {
template: '<div><slot>{{test()}}</slot></div>',
methods: {
test () {
test()
return 'test'
}
}
}
}
}).$mount()
expect(vm.$el.textContent).toBe('slot default')
expect(test).not.toHaveBeenCalled()
})

it('selector matching multiple elements', () => {
mount({
childTemplate: '<div><slot name="t"></slot></div>',
Expand Down
2 changes: 1 addition & 1 deletion test/unit/modules/compiler/codegen.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ describe('codegen', () => {
it('generate slot fallback content', () => {
assertCodegen(
'<div><slot><div>hi</div></slot></div>',
`with(this){return _c('div',[_t("default",[_c('div',[_v("hi")])])],2)}`
`with(this){return _c('div',[_t("default",function(){return [_c('div',[_v("hi")])]})],2)}`
)
})

Expand Down