Tabs 标签栏
基础用法
html
<vz-tabs v-model:current="currentActive" :list="tabsList"></vz-tabs>typescript
import { ref } from "vue";
const tabsList = ref([
{
value: "a",
label: "标签一",
},
{
value: "b",
label: "标签二",
},
{
value: "c",
label: "标签三",
},
]);
const currentActive = ref("a");禁用标签
html
<vz-tabs
v-model:current="currentActiveDisabled"
:list="tabsListDisabled"
@change="handleChange"
@click="handleClick"
></vz-tabs>typescript
import { ref } from "vue";
const tabsListDisabled = ref([
{
value: "a",
label: "标签一",
},
{
value: "b",
label: "标签二",
disabled: true,
},
{
value: "c",
label: "标签三",
},
]);
const currentActiveDisabled = ref("a");
function handleChange({ current, index }) {
console.log("CHANGE", current, index);
}
function handleClick({ current, index }) {
console.log("CLICK", current, index);
}标签栏滚动
html
<vz-tabs v-model:current="currentActiveScroll" :list="tabsListScroll"></vz-tabs>typescript
import { ref } from "vue";
const tabsListScroll = ref([
{
value: "a",
label: "标签一",
},
{
value: "b",
label: "标签二",
},
{
value: "c",
label: "标签三",
},
{
value: "d",
label: "标签四",
},
{
value: "e",
label: "标签五",
},
{
value: "f",
label: "标签六",
},
{
value: "g",
label: "标签七",
},
{
value: "h",
label: "标签八",
},
{
value: "i",
label: "标签九",
},
{
value: "j",
label: "标签十",
},
]);
const currentActiveScroll = ref("a");显示图标
html
<vz-tabs v-model:current="currentActiveIcon" :list="tabsListIcon"></vz-tabs>typescript
import { ref } from "vue";
const tabsListIcon = ref([
{
value: "a",
label: "标签一",
icon: "vz-icon-home",
},
{
value: "b",
label: "标签二",
icon: "vz-icon-home",
},
{
value: "c",
label: "标签三",
icon: "vz-icon-home",
},
]);
const currentActiveIcon = ref("a");显示徽章
html
<vz-tabs v-model:current="currentActiveBadge" :list="tabsListBadge"></vz-tabs>typescript
import { ref } from "vue";
const tabsListBadge = ref([
{
value: "a",
label: "标签一",
badge: "New",
},
{
value: "b",
label: "标签二",
badge: 1,
},
{
value: "c",
label: "标签三",
dot: true,
},
]);
const currentActiveBadge = ref("a");滑块宽度
html
<vz-tabs v-model:current="currentActiveBarWidth" :list="tabsListBarWidth" bar-width="auto"></vz-tabs>typescript
import { ref } from "vue";
const tabsListBarWidth = ref([
{
value: "a",
label: "标签一",
},
{
value: "b",
label: "标签二",
},
{
value: "c",
label: "标签三零三",
},
]);
const currentActiveBarWidth = ref("a");等分布局
html
<vz-tabs v-model:current="currentActiveEqual" :list="tabsListEqual" equal></vz-tabs>typescript
import { ref } from "vue";
const tabsListEqual = ref([
{
value: "a",
label: "标签一",
},
{
value: "b",
label: "标签二",
},
{
value: "c",
label: "标签三零三",
},
]);
const currentActiveEqual = ref("a");紧凑布局
html
<vz-tabs v-model:current="currentActiveDense" :list="tabsListDense" dense></vz-tabs>typescript
import { ref } from "vue";
const tabsListDense = ref([
{
value: "a",
label: "标签一",
},
{
value: "b",
label: "标签二",
},
{
value: "c",
label: "标签三",
},
]);
const currentActiveDense = ref("a");自定义颜色
html
<vz-tabs
v-model:current="currentActiveColor"
:list="tabsListColor"
active-color="var(--vz-color-success)"
inactive-color="var(--vz-text-color-thin)"
bar-height="10rpx"
bar-bg="linear-gradient(135deg, var(--vz-color-success), var(--vz-color-primary))"
bar-radius="10rpx 0 10rpx 0"
></vz-tabs>typescript
import { ref } from "vue";
const tabsListColor = ref([
{
value: "a",
label: "标签一",
},
{
value: "b",
label: "标签二",
},
{
value: "c",
label: "标签三",
},
]);
const currentActiveColor = ref("a");Props
| 属性名 | 说明 | 类型 | 默认值 |
|---|---|---|---|
| v-model:current / current | 当前选中的标签(value / index) | string / number | 0 |
| list | 标签列表 | TabsList | [] |
| active-color | 滑块和当前选中标签文字的颜色 | string | --vz-color-primary |
| inactive-color | 未选中时标签文字的颜色 | string | inherit |
| equal | 等分布局。未出现滚动条,且文字字数不同时才可看到效果 | boolean | false |
| dense | 紧凑布局。标签适应内容宽度 | boolean | false |
| px | 标签栏 padding | string / number | - |
| height | 标签栏高度 | string / number | --vz-height-base |
| bg | 标签栏背景 | string | - |
| item-px | 标签 padding | string / number | 16rpx |
| item-min-width | 标签最小宽度 | string / number | 20% |
| bar-width | 滑块宽度 | string / number | 60rpx |
| bar-height | 滑块高度 | string / number | 4rpx |
| bar-bg | 滑块背景 | string | --vz-color-primary |
| bar-radius | 滑块圆角 | string | --vz-height-base |
| i-class | 根节点样式类 | string | - |
| i-style | 根节点样式 | Vue.CSSProperties | - |
list
| 属性名 | 说明 | 类型 |
|---|---|---|
| label | 标签文案 | string |
| value | current 绑定值 | string / number |
| disabled | 是否禁用 | boolean |
| icon | 图标 | string |
| badge | 徽章显示值 | number / string |
| dot | 徽章是否以圆点形式显示 | boolean |
| offset | 徽章偏移量 [水平, 垂直] | [number, number] |
Events
| 事件名 | 说明 | 参数 |
|---|---|---|
| change | 选中的标签改变时触发 | { current, index } |
| click | 点击标签时触发 | { current, index } |
Slots
| 插槽名 | 说明 |
|---|---|
| default | 默认插槽 |
CSS
| 变量名 | 说明 | 默认值 |
|---|---|---|
| --vz-tabs-px | props.px | - |
| --vz-tabs-height | props.height | --vz-height-base |
| --vz-tabs-bg | props.bg | - |
| --vz-tabs-item-px | props.itemPx | 16rpx |
| --vz-tabs-item-min-width | props.itemMinWidth | 20% |
| --vz-tabs-active-color | props.activeColor | --vz-color-primary |
| --vz-tabs-inactive-color | props.inactiveColor | inherit |
| --vz-tabs-text-size | 文字大小 | inherit |
| --vz-tabs-disabled-color | 禁用时文字颜色 | --vz-text-color-disabled |
| --vz-tabs-icon-gap | 图标与文字之间的间距 | --vz-gap-base |
| --vz-tabs-bar-bottom | 滑块相对标签栏底部距离 | 0 |
| --vz-tabs-bar-width | props.barWidth | 60rpx |
| --vz-tabs-bar-height | props.barHeight | 4rpx |
| --vz-tabs-bar-bg | props.barBg | --vz-color-primary |
| --vz-tabs-bar-radius | props.barRadius | --vz-height-base |
SCSS
scss
$tabs: (
"item-px": 16rpx,
"item-min-width": 20%,
"height": getCssVar("height", "base"),
"active-color": getCssVar("color", "primary"),
"disabled-color": getCssVar("text-color", "disabled"),
"bar-bottom": 0,
"bar-width": 60rpx,
"bar-height": 4rpx,
"icon-gap": getCssVar("gap", "base"),
);