mirror of
https://gitee.com/vuejs/vue.git
synced 2024-12-02 20:17:52 +08:00
support <component :is="...">
This commit is contained in:
parent
a1ebdbbb7a
commit
3630bf1053
@ -17,6 +17,8 @@ function genElement (el) {
|
||||
return genRender(el)
|
||||
} else if (el.tag === 'slot') {
|
||||
return genSlot(el)
|
||||
} else if (el.tag === 'component') {
|
||||
return genComponent(el)
|
||||
} else {
|
||||
// if the element is potentially a component,
|
||||
// wrap its children as a thunk.
|
||||
@ -141,6 +143,10 @@ function genSlot (el) {
|
||||
return `($slots[${name}] || ${genChildren(el)})`
|
||||
}
|
||||
|
||||
function genComponent (el) {
|
||||
return `__h__(${el.component}, ${genData(el)}, ${genChildren(el, true)})`
|
||||
}
|
||||
|
||||
function genProps (props) {
|
||||
let res = ''
|
||||
for (let i = 0; i < props.length; i++) {
|
||||
|
@ -131,6 +131,7 @@ export function parse (template, options) {
|
||||
processIf(element)
|
||||
processRender(element)
|
||||
processSlot(element)
|
||||
processComponent(element)
|
||||
processClassBinding(element)
|
||||
processStyleBinding(element)
|
||||
processAttrs(element)
|
||||
@ -300,6 +301,15 @@ function processSlot (el) {
|
||||
}
|
||||
}
|
||||
|
||||
function processComponent (el) {
|
||||
if (el.tag === 'component') {
|
||||
let staticName = getAndRemoveAttr(el, 'is')
|
||||
el.component = staticName
|
||||
? JSON.stringify(staticName)
|
||||
: (getAndRemoveAttr(el, ':is') || getAndRemoveAttr(el, 'v-bind:is'))
|
||||
}
|
||||
}
|
||||
|
||||
function processClassBinding (el) {
|
||||
const staticClass = getAndRemoveAttr(el, 'class')
|
||||
el.staticClass = parseText(staticClass) || JSON.stringify(staticClass)
|
||||
|
@ -3,6 +3,9 @@ import { callHook } from '../instance/lifecycle'
|
||||
import { warn } from '../util/index'
|
||||
|
||||
export default function Component (Ctor, data, parent, children) {
|
||||
if (!Ctor) {
|
||||
return
|
||||
}
|
||||
if (typeof Ctor === 'object') {
|
||||
Ctor = Vue.extend(Ctor)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user