You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

5.3 KiB

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

title description spline isComponent
Tabs 选项卡 用于内容分类后的展示切换。 navigation true

引入

全局引入,在 miniprogram 根目录下的app.json中配置,局部引入,在需要引入的页面或组件的index.json中配置。

"usingComponents": {
  "t-tabs": "tdesign-miniprogram/tabs/tabs",
  "t-tab-panel": "tdesign-miniprogram/tab-panel/tab-panel"
}

代码演示

基础选项卡

{{ base }}

等距选项卡

{{ scroll }}

带图标选项卡

{{ with-icon }}

带徽章选项卡

{{ with-badge }}

带内容区选项卡

{{ with-content }}

选项卡状态

{{ status }}

选项卡尺寸

{{ size }}

选项卡样式

使用 theme 属性可以变换风格,支持 line = 线条默认tag = 标签card = 卡片

{{ theme }}

受控用法

<t-tabs value="{{value}}" bind:change="onTabsChange">
  <t-tab-panel label="标签页一" value="0">标签一内容</t-tab-panel>
  <t-tab-panel label="标签页二" value="1">标签二内容</t-tab-panel>
</t-tabs>
Page({
  data: {
    value: '0',
  },
  onTabsChange(e) {
    this.setData({ value: e.detail.value })
  },
});

与 Popup 使用

 <t-popup visible="{{visible}}" bind:visible-change="onVisibleChange">
  <t-tabs id="tabs" defaultValue="{{0}}" bind:change="onTabsChange" bind:click="onTabsClick" t-class="custom-tabs">
    <t-tab-panel label="标签页一" value="0">标签一内容</t-tab-panel>
    <t-tab-panel label="标签页二" value="1">标签二内容</t-tab-panel>
    <t-tab-panel label="标签页三" value="2">标签三内容</t-tab-panel>
  </t-tabs>
</t-popup>
Page({
  data: {
    visible: false
  },
  showPopup() {
    this.setData({
      visible: true
    }, () => {
      const tabs = this.selectComponent('tabs');

      tabs.setTrack(); // 这一步很重要,因为小程序的无法正确执行生命周期,所以需要手动设置下 tabs 的滑块
    })
  }
})

API

Tabs Props

名称 类型 默认值 说明 必传
animation Object - 动画效果设置。其中 duration 表示动画时长。TS 类型:TabAnimation type TabAnimation = { duration: number } & Record<string, any>详细类型定义 N
external-classes Array - 组件类名,分别用于设置 组件外层元素、选项卡单项、选项卡激活态、滚动条样式类名 等类名。['t-class', 't-class-item', 't-class-active', 't-class-track'] N
show-bottom-line Boolean true 是否展示底部激活线条 N
space-evenly Boolean true 选项卡头部空间是否均分 N
sticky Boolean false 是否开启粘性布局 N
sticky-props Object - 透传至 Sticky 组件。TS 类型:StickyPropsSticky API Documents详细类型定义 N
swipeable Boolean true 是否可以滑动切换 N
theme String line 标签的样式。可选项line/tag/card N
value String / Number - 激活的选项卡值。TS 类型:TabValue type TabValue = string | number详细类型定义 N
default-value String / Number undefined 激活的选项卡值。非受控属性。TS 类型:TabValue type TabValue = string | number详细类型定义 N

Tabs Events

名称 参数 描述
change (value: TabValue, label: string) 激活的选项卡发生变化时触发
click (value: TabValue, label: string) 点击选项卡时触发
scroll (scrollTop: number, isFixed: boolean) 页面滚动时触发

TabPanel Props

名称 类型 默认值 说明 必传
badge-props Object null 透传至 Badge 组件 N
destroy-on-hide Boolean true 【实现有误,暂不支持】选项卡内容隐藏时是否销毁 N
disabled Boolean false 是否禁用当前选项卡 N
icon String / Object - 1.0.0-rc.1。图标,传对象则透传至 Icon N
label String - 选项卡名称 N
panel String / Slot - 用于自定义选项卡面板内容 N
value String / Number - 选项卡的值唯一标识。TS 类型:TabValueTabs API Documents详细类型定义 N