From f6ab03fa7e58c49f32218bf9f83139913ef871cd Mon Sep 17 00:00:00 2001 From: neverland Date: Sat, 16 Feb 2019 11:10:40 +0800 Subject: [PATCH] [improvement] support functional component model prop (#2758) --- packages/utils/use/sfc.ts | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/packages/utils/use/sfc.ts b/packages/utils/use/sfc.ts index 92da4da53..6b3274ad3 100644 --- a/packages/utils/use/sfc.ts +++ b/packages/utils/use/sfc.ts @@ -11,20 +11,31 @@ import Vue, { RenderContext } from 'vue/types'; import { VNode, ScopedSlot } from 'vue/types/vnode'; +import { InjectOptions, PropsDefinition } from 'vue/types/options'; type VantComponentOptions = ComponentOptions & { functional?: boolean; install?: (Vue: VueConstructor) => void; }; -type VantPureComponent = { +type DefaultProps = Record; + +type VantPureComponent< + Props = DefaultProps, + PropDefs = PropsDefinition +> = { ( h: CreateElement, props: { [key: string]: any }, slots: { [key: string]: ScopedSlot | undefined }, context: RenderContext ): VNode; - props: any; + props?: PropDefs; + model?: { + prop?: string; + event?: string; + }; + inject?: InjectOptions; }; const arrayProp = { @@ -73,6 +84,7 @@ function transformPureComponent(pure: VantPureComponent): VantComponentOptions { return { functional: true, props: pure.props, + model: pure.model, render: (h, context) => pure(h, context.props, unifySlots(context), context) }; }