mirror of
https://gitee.com/vant-contrib/vant.git
synced 2025-04-06 03:57:59 +08:00
[improvement] support functional component model prop (#2758)
This commit is contained in:
parent
9aee819c29
commit
f6ab03fa7e
@ -11,20 +11,31 @@ import Vue, {
|
|||||||
RenderContext
|
RenderContext
|
||||||
} from 'vue/types';
|
} from 'vue/types';
|
||||||
import { VNode, ScopedSlot } from 'vue/types/vnode';
|
import { VNode, ScopedSlot } from 'vue/types/vnode';
|
||||||
|
import { InjectOptions, PropsDefinition } from 'vue/types/options';
|
||||||
|
|
||||||
type VantComponentOptions = ComponentOptions<Vue> & {
|
type VantComponentOptions = ComponentOptions<Vue> & {
|
||||||
functional?: boolean;
|
functional?: boolean;
|
||||||
install?: (Vue: VueConstructor) => void;
|
install?: (Vue: VueConstructor) => void;
|
||||||
};
|
};
|
||||||
|
|
||||||
type VantPureComponent = {
|
type DefaultProps = Record<string, any>;
|
||||||
|
|
||||||
|
type VantPureComponent<
|
||||||
|
Props = DefaultProps,
|
||||||
|
PropDefs = PropsDefinition<Props>
|
||||||
|
> = {
|
||||||
(
|
(
|
||||||
h: CreateElement,
|
h: CreateElement,
|
||||||
props: { [key: string]: any },
|
props: { [key: string]: any },
|
||||||
slots: { [key: string]: ScopedSlot | undefined },
|
slots: { [key: string]: ScopedSlot | undefined },
|
||||||
context: RenderContext
|
context: RenderContext
|
||||||
): VNode;
|
): VNode;
|
||||||
props: any;
|
props?: PropDefs;
|
||||||
|
model?: {
|
||||||
|
prop?: string;
|
||||||
|
event?: string;
|
||||||
|
};
|
||||||
|
inject?: InjectOptions;
|
||||||
};
|
};
|
||||||
|
|
||||||
const arrayProp = {
|
const arrayProp = {
|
||||||
@ -73,6 +84,7 @@ function transformPureComponent(pure: VantPureComponent): VantComponentOptions {
|
|||||||
return {
|
return {
|
||||||
functional: true,
|
functional: true,
|
||||||
props: pure.props,
|
props: pure.props,
|
||||||
|
model: pure.model,
|
||||||
render: (h, context) => pure(h, context.props, unifySlots(context), context)
|
render: (h, context) => pure(h, context.props, unifySlots(context), context)
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user