feat: inheritAttrs
This commit is contained in:
parent
ddd55fae54
commit
b5db956f9a
@ -21,6 +21,7 @@ export interface ComponentClass extends Flatten<typeof Component> {
|
|||||||
export interface FunctionalComponent<P = Data> extends RenderFunction<P> {
|
export interface FunctionalComponent<P = Data> extends RenderFunction<P> {
|
||||||
pure?: boolean
|
pure?: boolean
|
||||||
props?: ComponentPropsOptions<P>
|
props?: ComponentPropsOptions<P>
|
||||||
|
inheritAttrs?: boolean
|
||||||
}
|
}
|
||||||
|
|
||||||
// this interface is merged with the class type
|
// this interface is merged with the class type
|
||||||
|
@ -13,6 +13,7 @@ export interface ComponentOptions<D = Data, P = Data> {
|
|||||||
computed?: ComponentComputedOptions<D, P>
|
computed?: ComponentComputedOptions<D, P>
|
||||||
watch?: ComponentWatchOptions<D, P>
|
watch?: ComponentWatchOptions<D, P>
|
||||||
render?: RenderFunction<P>
|
render?: RenderFunction<P>
|
||||||
|
inheritAttrs?: boolean
|
||||||
// TODO other options
|
// TODO other options
|
||||||
readonly [key: string]: any
|
readonly [key: string]: any
|
||||||
}
|
}
|
||||||
|
@ -71,7 +71,11 @@ export function renderInstanceRoot(instance: MountedComponent) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return normalizeComponentRoot(vnode, instance.$parentVNode)
|
return normalizeComponentRoot(
|
||||||
|
vnode,
|
||||||
|
instance.$parentVNode,
|
||||||
|
instance.$options.inheritAttrs
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
export function teardownComponentInstance(instance: MountedComponent) {
|
export function teardownComponentInstance(instance: MountedComponent) {
|
||||||
@ -88,7 +92,8 @@ export function teardownComponentInstance(instance: MountedComponent) {
|
|||||||
|
|
||||||
export function normalizeComponentRoot(
|
export function normalizeComponentRoot(
|
||||||
vnode: any,
|
vnode: any,
|
||||||
componentVNode: VNode | null
|
componentVNode: VNode | null,
|
||||||
|
inheritAttrs: boolean | void
|
||||||
): VNode {
|
): VNode {
|
||||||
if (vnode == null) {
|
if (vnode == null) {
|
||||||
vnode = createTextVNode('')
|
vnode = createTextVNode('')
|
||||||
@ -104,7 +109,7 @@ export function normalizeComponentRoot(
|
|||||||
(flags & VNodeFlags.COMPONENT || flags & VNodeFlags.ELEMENT)
|
(flags & VNodeFlags.COMPONENT || flags & VNodeFlags.ELEMENT)
|
||||||
) {
|
) {
|
||||||
const parentData = componentVNode.data
|
const parentData = componentVNode.data
|
||||||
if (parentData != null) {
|
if (parentData != null && inheritAttrs !== false) {
|
||||||
let extraData: any = null
|
let extraData: any = null
|
||||||
for (const key in parentData) {
|
for (const key in parentData) {
|
||||||
// attrs/class/style bindings on parentVNode are merged down to child
|
// attrs/class/style bindings on parentVNode are merged down to child
|
||||||
|
@ -278,7 +278,8 @@ export function createRenderer(options: RendererOptions) {
|
|||||||
// functional component
|
// functional component
|
||||||
const subTree = (vnode.children = normalizeComponentRoot(
|
const subTree = (vnode.children = normalizeComponentRoot(
|
||||||
(tag as FunctionalComponent)(data || EMPTY_OBJ, slots || EMPTY_OBJ),
|
(tag as FunctionalComponent)(data || EMPTY_OBJ, slots || EMPTY_OBJ),
|
||||||
vnode
|
vnode,
|
||||||
|
(tag as FunctionalComponent).inheritAttrs
|
||||||
))
|
))
|
||||||
el = vnode.el = mount(subTree, null, parentComponent, isSVG, null)
|
el = vnode.el = mount(subTree, null, parentComponent, isSVG, null)
|
||||||
}
|
}
|
||||||
@ -562,7 +563,8 @@ export function createRenderer(options: RendererOptions) {
|
|||||||
if (shouldUpdate) {
|
if (shouldUpdate) {
|
||||||
const nextTree = (nextVNode.children = normalizeComponentRoot(
|
const nextTree = (nextVNode.children = normalizeComponentRoot(
|
||||||
render(nextProps || EMPTY_OBJ, nextSlots || EMPTY_OBJ),
|
render(nextProps || EMPTY_OBJ, nextSlots || EMPTY_OBJ),
|
||||||
nextVNode
|
nextVNode,
|
||||||
|
render.inheritAttrs
|
||||||
))
|
))
|
||||||
patch(prevTree, nextTree, container, parentComponent, isSVG)
|
patch(prevTree, nextTree, container, parentComponent, isSVG)
|
||||||
nextVNode.el = nextTree.el
|
nextVNode.el = nextTree.el
|
||||||
|
Loading…
Reference in New Issue
Block a user