Skip to content

Commit 4e12b25

Browse files
committed
simplify functional component usage
1 parent dab4db8 commit 4e12b25

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

src/core/vdom/create-functional-component.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { resolveSlots } from '../instance/render-helpers/resolve-slots'
66

77
import {
88
isDef,
9+
camelize,
910
validateProp
1011
} from '../util/index'
1112

@@ -22,13 +23,17 @@ export function createFunctionalComponent (
2223
for (const key in propOptions) {
2324
props[key] = validateProp(key, propOptions, propsData)
2425
}
26+
} else {
27+
if (isDef(data.attrs)) mergeProps(props, data.attrs)
28+
if (isDef(data.props)) mergeProps(props, data.props)
2529
}
2630
// ensure the createElement function in functional components
2731
// gets a unique context - this is necessary for correct named slot check
2832
const _context = Object.create(context)
2933
const h = (a, b, c, d) => createElement(_context, a, b, c, d, true)
3034
const vnode = Ctor.options.render.call(null, h, {
3135
props,
36+
listeners: data.on || {},
3237
data,
3338
parent: context,
3439
children,
@@ -42,3 +47,9 @@ export function createFunctionalComponent (
4247
}
4348
return vnode
4449
}
50+
51+
function mergeProps (to, from) {
52+
for (const key in from) {
53+
to[camelize(key)] = from[key]
54+
}
55+
}

0 commit comments

Comments
 (0)