|
18 | 18 | | onPlusClick | ‘+’icon被点击时的回调 | () => {} | | false | |
19 | 19 | | onTabClick | tab 被点击的回调 | (index: Number) => void | | false | |
20 | 20 | | onChange | tab变化时触发 | (index: Number) => void | | false | |
21 | | -| swipeable | 是否可以滑动内容切换 | Boolean | true | false | |
| 21 | +| swipeable | 是否可以滑动内容切换,同时可控制高度是否自适应 | Boolean | true | false | |
22 | 22 | | duration | 当swipeable为true时滑动动画时长,单位ms | Number | 500(ms) | false | |
23 | 23 | | tabBarBackgroundColor | tabBar背景色 | String | | false | |
24 | 24 | | tabBarActiveTextColor | tabBar激活Tab文字颜色 | String | | false | |
|
34 | 34 | | 属性名 | 描述 | 类型 | 默认值 | 必选 | |
35 | 35 | | ---- | ---- | ---- | ---- | ---- | |
36 | 36 | | index | 列表项的唯一索引 | String | | | | |
| 37 | +| tabId | tab 内容序列索引 | Number | {{index}} | | | |
| 38 | +| activeTab | 选项卡当前激活序列索引 | Number | {{activeTab}} | | | |
| 39 | + |
| 40 | +## tab-content 高度自适应说明 |
| 41 | + |
| 42 | +tabs 组件内容区域高度是否能够自适应,需要注意 `swipeable` 的值: |
| 43 | + |
| 44 | +* `swipeable='{{true}}'`:内容区域可滑动,且相对应 tab 标签卡;但**内容区域高度为固定值**,需要在 acss 文件中设定 `height` 值,否则高度会异常; |
| 45 | +* `swipeable='{{false}}'`:内容区域不可滑动,此时高度表现形式有两种,且可以不需要在 acss 文件设定 `height` 值; |
| 46 | + * `<tab-content>` 中**无** `tabId` 和 `activeTab` 两个属性,此时的高度将以所有内容区域中最高的为基准展示; |
| 47 | + * `<tab-content>` 中**包含** `tabId` 和 `activeTab` 两个属性时 `tabId="{{index}}" activeTab="{{activeTab}}"`,内容区域所展示的高度将会随着不同模块的高度而改变; |
37 | 48 |
|
38 | 49 | ## 示例 |
39 | 50 |
|
|
56 | 67 | onChange="handleTabChange" |
57 | 68 | onPlusClick="handlePlusClick" |
58 | 69 | activeTab="{{activeTab}}" |
| 70 | + swipeable="{{false}}" |
59 | 71 | > |
60 | 72 | <block a:for="{{tabs}}"> |
61 | | - <tab-content key="{{index}}"> |
| 73 | + <tab-content key="{{index}}" tabId="{{index}}" activeTab="{{activeTab}}" a:if="{{index === 1}}"> |
| 74 | + <view class="tab-content" style="height: 100px;">高度为 100px {{item.title}}</view> |
| 75 | + </tab-content> |
| 76 | + <tab-content key="{{index}}" tabId="{{index}}" activeTab="{{activeTab}}" a:elif="{{index === 2}}"> |
| 77 | + <view class="tab-content" style="height: 200px;">改变 tab-content 高度为 200px {{item.title}}</view> |
| 78 | + </tab-content> |
| 79 | + <tab-content key="{{index}}" tabId="{{index}}" activeTab="{{activeTab}}" a:else> |
62 | 80 | <view class="tab-content">content of {{item.title}}</view> |
63 | 81 | </tab-content> |
64 | 82 | </block> |
@@ -108,6 +126,8 @@ Page({ |
108 | 126 | display: flex; |
109 | 127 | justify-content: center; |
110 | 128 | align-items: center; |
111 | | - height: 300px; |
| 129 | + padding: 40rpx; |
| 130 | + /* 如果 swipeable="{{true}}",需要增加 height */ |
| 131 | + /* height: 350px; */ |
112 | 132 | } |
113 | 133 | ``` |
0 commit comments