Skip to content

TabView-示例


数据结构


  1. items
javascript
items = [
    {
        key: 'explorer',
        name: '资源管理器',
        title: '资源管理器',
        show: true,
        disabled: false,
        draggable: true,
        closable: true,
        modified: false,
        icon: 'FolderHorizontal',
        img: ''
    }
]

modified 也支持传入函数,会通过 valueTrigger 计算,因此可以按标签项动态决定是否显示“未保存”状态。

属性


属性类型必填默认值说明
modelValueobjectnull当前选中的标签项。
itemsarray[{ name: 'Tab' }]标签项数组。单项通常使用 keynametitle,并可选传入 iconimgimagesrc
itemWidthnumber / string180所有标签统一宽度。
itemHeightnumber / string38标签高度。
paddingstring''组件外层内边距。
borderRadiusnumber / string8组件外层圆角。
foregroundstring''普通标签的文字和图标颜色。
choosenForegroundstring''选中标签的文字和图标颜色。
chooseBackgroundstring''选中标签的背景色。
backgroundstring''整个 TabView 的背景色。
normalBackgroundstring''标签项普通状态下的背景色。
hoverBackgroundstring''标签悬停时的背景色。
activeBackgroundstring''标签按下时的背景色。
fontSizenumber / string13标签标题字号。
imgBorderRadiusnumber / string4标签图片圆角。
draggablebooleantrue是否允许拖拽调整标签顺序。
closablebooleantrue是否默认显示关闭按钮。单项可通过 closable: false 单独关闭。
listPaddingstring''标签列表内部容器的内边距。
itemBorderRadiusnumber / string8每个标签项的圆角。
showAddButtonbooleanfalse是否显示右侧添加按钮。
addButtonIconstring'Add'添加按钮使用的 Fluent 图标名。
addButtonBackgroundstring''添加按钮背景色。
addButtonForegroundstring''添加按钮前景色。
closeButtonIconstring'ChromeClose'关闭按钮使用的 Fluent 图标名。
closeIconSizenumber / string10关闭按钮图标大小。
modifiedButtonIconstring'CircleFill'已修改标签在未 hover 时显示的 Fluent 图标名。
modifiedIconSizenumber / string8已修改状态指示图标大小。
beforeClosefunction() => true关闭标签前的拦截函数。接收 { event, item, items, index },只有返回 true 时才会继续关闭。
closeButtonForegroundstring''关闭按钮前景色。
styleModestring'borderless'标签的视觉样式。当前支持 borderlessrounded
overflowModestring'scroll'多标签溢出时的处理方式。scroll 保持标签宽度并启用横向滚动,shrink 会把标签压缩到同一行内。
themestring'global'主题样式,支持 globallightdarksystemcustom
disabledbooleanfalse是否禁用整个组件。
langstring'global'从公共属性继承的语言选项。

插槽


  1. item

自定义整个标签项内容。使用后会替换默认的“图标 + 标题”布局。

  • item: 当前标签项
  • index: 当前标签索引
  • eqal: 返回当前标签是否被选中
  • valueTrigger: 用于读取标签项上的静态值或函数返回值
vue
<template v-slot:item="{ item, index, eqal, valueTrigger }">
    <div
        style="display: flex; align-items: center; gap: 8px;"
    >
        <i
            class="ms-Icon"
            :class="`ms-Icon--${valueTrigger(item.icon)}`"
        ></i>
        <b>{{ valueTrigger(item.name) }}</b>
        <span v-if="eqal(item)">当前</span>
    </div>
</template>
  1. icon

仅自定义默认布局中的图标区域。如果已经使用 item 完整自定义标签项,则此插槽不会生效。

  • item: 当前标签项
  • index: 当前标签索引
  • eqal: 返回当前标签是否被选中
  • valueTrigger: 用于读取标签项上的静态值或函数返回值
vue
<template v-slot:icon="{ item, valueTrigger }">
    <i
        class="ms-Icon"
        :class="`ms-Icon--${valueTrigger(item.icon)}`"
        style="font-size: 18px;"
    ></i>
</template>
  1. close-button

自定义可关闭标签上的关闭按钮内容。

  • item: 当前标签项
  • index: 当前标签索引
  • modified: 当前标签项是否处于已修改状态
vue
<template v-slot:close-button="{ item, modified }">
    <i
        class="ms-Icon"
        :class="modified ? 'ms-Icon--CircleFill' : 'ms-Icon--Cancel'"
        :title="item.name"
    ></i>
</template>
  1. add-button

自定义右侧添加按钮内容,仅在 showAddButtontrue 时显示。

vue
<template v-slot:add-button>
    <i class="ms-Icon ms-Icon--Add"></i>
</template>

事件


事件名参数说明
update:modelValueobject选中标签变更时触发。
update:itemsarray关闭标签或拖拽重排后触发,返回新的标签列表。
changeobject选中标签变更时触发。
clickobject点击标签时触发,返回当前被点击的标签项。
addevent点击添加按钮时触发。
closeobject关闭标签时触发,返回 eventitemitemsindex
reorderobject拖拽重排完成后触发,返回 itemitemsfromto

MIT Licensed