From 25cbdecf250d4203a882ef4587ef8345ea039893 Mon Sep 17 00:00:00 2001 From: chenjiahan Date: Tue, 25 Aug 2020 15:24:30 +0800 Subject: [PATCH] chore: add useParent default value --- src/action-bar-icon/index.js | 3 +-- src/api/use-relation.ts | 7 +++++-- src/collapse-item/index.js | 2 +- src/sidebar-item/index.js | 5 ++--- src/sidebar/index.js | 1 - 5 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/action-bar-icon/index.js b/src/action-bar-icon/index.js index 39a0ad1ce..9799c8c0e 100644 --- a/src/action-bar-icon/index.js +++ b/src/action-bar-icon/index.js @@ -1,4 +1,3 @@ -import { ref } from 'vue'; import { createNamespace } from '../utils'; import { route, routeProps } from '../utils/router'; import { useParent } from '../api/use-relation'; @@ -20,7 +19,7 @@ export default createComponent({ }, setup(props, { slots }) { - useParent(ACTION_BAR_KEY, ref()); + useParent(ACTION_BAR_KEY); const renderIcon = () => { const { dot, badge, icon, color, iconClass } = props; diff --git a/src/api/use-relation.ts b/src/api/use-relation.ts index 857ebf04d..96fffc4c3 100644 --- a/src/api/use-relation.ts +++ b/src/api/use-relation.ts @@ -1,10 +1,13 @@ -import { Ref, inject, computed, onUnmounted } from 'vue'; +import { ref, Ref, inject, computed, onUnmounted } from 'vue'; export type Parent = null | { children: Ref[]>; }; -export function useParent(key: string, child: Ref) { +export function useParent( + key: string, + child: Ref = ref() as Ref +) { const parent = inject>(key, null); if (parent) { diff --git a/src/collapse-item/index.js b/src/collapse-item/index.js index 201609be4..8e5d36350 100644 --- a/src/collapse-item/index.js +++ b/src/collapse-item/index.js @@ -29,7 +29,7 @@ export default createComponent({ setup(props, { slots }) { const wrapper = ref(null); const content = ref(null); - const { parent, index } = useParent(COLLAPSE_KEY, ref()); + const { parent, index } = useParent(COLLAPSE_KEY); const currentName = computed(() => isDef(props.name) ? props.name : index.value diff --git a/src/sidebar-item/index.js b/src/sidebar-item/index.js index e201b3b03..3b84e3570 100644 --- a/src/sidebar-item/index.js +++ b/src/sidebar-item/index.js @@ -1,4 +1,3 @@ -import { ref } from 'vue'; import { createNamespace } from '../utils'; import { route, routeProps } from '../utils/router'; import { useParent } from '../api/use-relation'; @@ -19,7 +18,7 @@ export default createComponent({ emits: ['click'], setup(props, { emit }) { - const { parent, index } = useParent(SIDEBAR_KEY, ref()); + const { parent, index } = useParent(SIDEBAR_KEY); return (vm) => { const { dot, badge, title, disabled } = props; @@ -37,7 +36,7 @@ export default createComponent({ }; return ( - +
{title} diff --git a/src/sidebar/index.js b/src/sidebar/index.js index 61181e177..e29ae8a1b 100644 --- a/src/sidebar/index.js +++ b/src/sidebar/index.js @@ -18,7 +18,6 @@ export default createComponent({ setup(props, { emit, slots }) { const children = ref([]); const active = () => +props.modelValue; - const setActive = (value) => { if (value !== active()) { emit('change', value);