-
Notifications
You must be signed in to change notification settings - Fork 668
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7b28af6
commit 5fecbd2
Showing
6 changed files
with
176 additions
and
44 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
// @flow | ||
|
||
import { compileToFunctions } from 'vue-template-compiler' | ||
|
||
function createVNodes ( | ||
vm: Component, | ||
slotValue: string | ||
): Array<VNode> { | ||
const el = compileToFunctions(`<div>${slotValue}</div>`) | ||
const _staticRenderFns = vm._renderProxy.$options.staticRenderFns | ||
// version < 2.5 | ||
if (!vm._renderProxy._staticTrees) { | ||
vm._renderProxy._staticTrees = [] | ||
} | ||
vm._renderProxy.$options.staticRenderFns = el.staticRenderFns | ||
const vnode = el.render.call(vm._renderProxy, vm.$createElement) | ||
vm._renderProxy.$options.staticRenderFns = _staticRenderFns | ||
return vnode.children | ||
} | ||
|
||
function createVNodesForSlot ( | ||
vm: Component, | ||
slotValue: SlotValue, | ||
name: string, | ||
): VNode | string { | ||
let vnode | ||
if (typeof slotValue === 'string') { | ||
const vnodes = createVNodes(vm, slotValue) | ||
vnode = vnodes[0] | ||
} else { | ||
vnode = vm.$createElement(slotValue) | ||
} | ||
if (vnode.data) { | ||
vnode.data.slot = name | ||
} else { | ||
vnode.data = { slot: name } | ||
} | ||
return vnode | ||
} | ||
|
||
export function createSlotVNodes ( | ||
vm: Component, | ||
slots: SlotsObject | ||
): Array<VNode | string> { | ||
return Object.keys(slots).reduce((acc, key) => { | ||
const content = slots[key] | ||
if (Array.isArray(content)) { | ||
const nodes = content.map( | ||
slotDef => createVNodesForSlot(vm, slotDef, key) | ||
) | ||
return acc.concat(nodes) | ||
} | ||
|
||
return acc.concat(createVNodesForSlot(vm, content, key)) | ||
}, []) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<template> | ||
<div><span baz="qux">{{ fromLocalVue }},{{ bar }}</span></div> | ||
</template> | ||
|
||
<script> | ||
export default{ | ||
name: 'component-with-parent-name', | ||
props: ['fromLocalVue'], | ||
data () { | ||
return { | ||
bar: 'quux' | ||
} | ||
}, | ||
mounted () { | ||
this.$parent.childComponentName = this.$options.name | ||
} | ||
} | ||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters