-
-
Notifications
You must be signed in to change notification settings - Fork 163
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
142 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,49 @@ | ||
<script lang="ts" setup> | ||
import { Props } from './props' | ||
import { TABS_PROPS_KEY } from '../../tabs/src/props' | ||
import { inject, computed } from 'vue' | ||
import { inject, computed, getCurrentInstance, ref, onMounted, reactive } from 'vue' | ||
import type { ComponentInternalInstance } from 'vue' | ||
defineOptions({ name: 'FTabsItem' }) | ||
const prop = defineProps(Props) | ||
/** 获取当前组件实例 */ | ||
const instance = getCurrentInstance() as ComponentInternalInstance | ||
const paneName = ref(prop.name) | ||
/** 获取父组件注入的依赖项 */ | ||
const parentInject = inject(TABS_PROPS_KEY, null) | ||
const pane = reactive({ | ||
paneName, | ||
label: prop.label, | ||
uid: instance.uid, | ||
prop | ||
}) | ||
/** 该组件是否显示 */ | ||
const isShow = computed( | ||
(): boolean | null => parentInject && parentInject.activeName.value === prop.name | ||
(): boolean | null => parentInject && parentInject.activeName.value === pane.paneName | ||
) | ||
/** 在组件插入及卸载时都要更新父级的 pane 列表 */ | ||
onMounted((): void => { | ||
parentInject && parentInject.registerChild(pane) | ||
}) | ||
// onBeforeUnmount((): void => { | ||
// parentInject && parentInject.unRegisterChild(pane) | ||
// }) | ||
</script> | ||
|
||
<template> | ||
<div v-show="isShow" class="f-tabs-item" role="tabpanel"> | ||
<div | ||
v-show="isShow" | ||
:class="['f-tabs-item', { 'f-tabs-item__active': isShow }]" | ||
role="tabpanel" | ||
> | ||
<slot /> | ||
</div> | ||
</template> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,4 @@ | ||
.f-tabs-item { | ||
padding: 4px 8px; | ||
box-sizing: border-box; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,18 @@ | ||
<script lang="ts" setup> | ||
import { ref } from 'vue' | ||
const name = ref('2') | ||
</script> | ||
<script lang="ts" setup></script> | ||
|
||
<template> | ||
{{ name }} | ||
<f-tabs v-model="name"> | ||
<f-tabs-item name="1" label="如烟"> | ||
<f-tabs> | ||
<f-tabs-item label="如烟"> | ||
<p>七岁的那一年,抓住那只蝉,以为能抓住夏天;</p> | ||
<p>十七岁的那年,吻过他的脸,就以为和他能永远。</p> | ||
</f-tabs-item> | ||
<f-tabs-item name="2" label="盛夏光年"> | ||
<f-tabs-item label="盛夏光年"> | ||
<p>长大 难道是人必经的溃烂。</p> | ||
</f-tabs-item> | ||
<f-tabs-item name="3" label="我心中尚未崩坏的地方"> | ||
<f-tabs-item label="我心中尚未崩坏的地方"> | ||
<p>就算会有一天,没人与我合唱,至少在我的心中,还有个尚未崩坏的地方。</p> | ||
</f-tabs-item> | ||
</f-tabs> | ||
</template> | ||
|
||
<style lang="scss" scoped></style> |