mirror of
https://gitee.com/vant-contrib/vant.git
synced 2025-04-06 03:57:59 +08:00
fix: useParent default value
This commit is contained in:
parent
63f15094f3
commit
ee256e591c
@ -24,6 +24,7 @@ export default createComponent({
|
||||
|
||||
setup(props, { slots }) {
|
||||
const route = useRoute();
|
||||
|
||||
useParent(ACTION_BAR_KEY);
|
||||
|
||||
const renderIcon = () => {
|
||||
@ -51,7 +52,7 @@ export default createComponent({
|
||||
};
|
||||
|
||||
return () => (
|
||||
<div role="button" class={bem()} tabindex="0" onClick={route}>
|
||||
<div role="button" class={bem()} tabindex={0} onClick={route}>
|
||||
{renderIcon()}
|
||||
{slots.default ? slots.default() : props.text}
|
||||
</div>
|
@ -4,7 +4,10 @@ type Parent = { children: unknown[] };
|
||||
|
||||
type Child<T> = T extends { children: (infer U)[] } ? U : never;
|
||||
|
||||
export function useParent<P extends Parent>(key: string, child: Child<P>) {
|
||||
export function useParent<P extends Parent>(
|
||||
key: string,
|
||||
child = {} as Child<P>
|
||||
) {
|
||||
const parent = inject<P | null>(key, null);
|
||||
|
||||
if (parent) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user