Skip to content

Tab 选项卡

通过 items 声明标签项,并以 v-model 双向绑定当前选中索引。支持顶部标签栏(tab)、顶部面板(top)与内容面板(panel)多段插槽,便于定制丰富的选项卡布局。

基础用法

标签一
标签二
标签三
面板内容 1:标签一
面板内容 2:标签二
面板内容 3:标签三
查看代码
vue
<template>
    <Tab v-model="active" :items="items">
        <template #default="{ index, item, active }">
            <span class="tab-item" :class="{ active }">{{ item.label }}</span>
        </template>
        <template #panel="{ item, index }">
            <div style="padding: 16px; border: 1px solid #eee; border-radius: 8px">面板内容 {{ index + 1 }}:{{ item.label }}</div>
        </template>
    </Tab>
</template>

<script setup lang="ts">
import { ref } from "vue";
import { Tab } from "@a-drowned-fish/rox-v";

const active = ref(0);
const items = [
    { key: "1", label: "标签一" },
    { key: "2", label: "标签二" },
    { key: "3", label: "标签三" },
];
</script>
<style>
.tab-item {
    display: flex;
    height: 36px;
    padding: 10px 0;
    color: #1a171b;
    opacity: 0.32;
    align-items: center;
    transition: opacity 200ms linear;
}

.tab-item.active {
    opacity: 1;
}
</style>

Props

参数说明类型默认值
modelValue (v-model)当前选中索引number0
items标签项数组,每项需包含 labelArray[]
trigger触发切换方式"click" | "hover""click"
dir文字方向"ltr" | "rtl""ltr"
animate是否启用切换动画booleantrue
gap标签之间间距string
allowWheel是否支持滚轮切换booleanfalse
itemShowInCenter激活项是否滚动到可视区中央booleanfalse
tabContainerClass / tabItemClass标签容器 / 标签项类名string""
topPanelContainerClass / topPanelItemClass顶部面板容器 / 项类名string""
panelContainerClass / panelItemClass内容面板容器 / 项类名string""
activeLineClass激活指示条类名string""

事件

事件名说明回调参数
update:modelValue选中索引变化(index: number) => void

插槽

插槽名子作用域说明
default{ item, index, active }内容面板(同 panel
tab{ item, index, active }自定义标签栏项
top{ item, index, active }顶部面板项
panel{ item, index, active }内容面板项
middle标签栏与内容区之间的自定义内容

方法(expose)

方法说明
moveTo(index)程序化切换到指定索引

基于 MIT 协议开源