diff --git a/packages/create-instance/create-slot-vnodes.js b/packages/create-instance/create-slot-vnodes.js index dfa8edd44..b9e42e8a1 100644 --- a/packages/create-instance/create-slot-vnodes.js +++ b/packages/create-instance/create-slot-vnodes.js @@ -4,9 +4,12 @@ import { compileToFunctions } from 'vue-template-compiler' function createVNodes ( vm: Component, - slotValue: string + slotValue: string, + name ): Array { - const el = compileToFunctions(`
${slotValue}
`) + const el = compileToFunctions( + `
` + ) const _staticRenderFns = vm._renderProxy.$options.staticRenderFns const _staticTrees = vm._renderProxy._staticTrees vm._renderProxy._staticTrees = [] @@ -14,7 +17,7 @@ function createVNodes ( const vnode = el.render.call(vm._renderProxy, vm.$createElement) vm._renderProxy.$options.staticRenderFns = _staticRenderFns vm._renderProxy._staticTrees = _staticTrees - return vnode.children + return vnode.children[0] } function createVNodesForSlot ( @@ -22,21 +25,11 @@ function createVNodesForSlot ( slotValue: SlotValue, name: string, ): VNode | Array { - let vnode if (typeof slotValue === 'string') { - const vnodes = createVNodes(vm, slotValue) - if (vnodes.length > 1) { - return vnodes - } - vnode = vnodes[0] - } else { - vnode = vm.$createElement(slotValue) - } - if (vnode.data) { - vnode.data.slot = name - } else { - vnode.data = { slot: name } + return createVNodes(vm, slotValue, name) } + const vnode = vm.$createElement(slotValue) + ;(vnode.data || (vnode.data = {})).slot = name return vnode } diff --git a/test/specs/mounting-options/slots.spec.js b/test/specs/mounting-options/slots.spec.js index 38d484532..5d70a404d 100644 --- a/test/specs/mounting-options/slots.spec.js +++ b/test/specs/mounting-options/slots.spec.js @@ -237,14 +237,14 @@ describeWithMountingMethods('options.slots', mountingMethod => { it('mounts component with default and named text slot', () => { const wrapper = mountingMethod(ComponentWithSlots, { slots: { - default: 'hello,', - footer: '' + footer: 'world', + default: 'hello,' } }) if (mountingMethod.name === 'renderToString') { - expect(wrapper).contains('hello,world') + expect(wrapper).contains('hello,