fix: useParent default value

This commit is contained in:
chenjiahan 2020-09-21 18:54:43 +08:00
parent 63f15094f3
commit ee256e591c
2 changed files with 6 additions and 2 deletions

View File

@ -24,6 +24,7 @@ export default createComponent({
setup(props, { slots }) { setup(props, { slots }) {
const route = useRoute(); const route = useRoute();
useParent(ACTION_BAR_KEY); useParent(ACTION_BAR_KEY);
const renderIcon = () => { const renderIcon = () => {
@ -51,7 +52,7 @@ export default createComponent({
}; };
return () => ( return () => (
<div role="button" class={bem()} tabindex="0" onClick={route}> <div role="button" class={bem()} tabindex={0} onClick={route}>
{renderIcon()} {renderIcon()}
{slots.default ? slots.default() : props.text} {slots.default ? slots.default() : props.text}
</div> </div>

View File

@ -4,7 +4,10 @@ type Parent = { children: unknown[] };
type Child<T> = T extends { children: (infer U)[] } ? U : never; 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); const parent = inject<P | null>(key, null);
if (parent) { if (parent) {