Tabs 导航切换栏

使用指南

在 page.json 中引入组件

  1. "usingComponents": {
  2. "w-tabs": "wuss-weapp/w-tabs/index",
  3. }

视频演示

代码演示

  1. <w-pane title="Tabs" desc="导航切换栏" />
  2. <w-pane desc="Default" />
  3. <w-tabs bind:onChange="handleChange" options="{{ tabs1 }}" />
  4. <w-pane desc="Initial Index = 2" />
  5. <w-button type="info" bind:onClick="handleSelected">selected tab2</w-button>
  6. <w-tabs
  7. bind:onChange="handleChange"
  8. options="{{ tabs4 }}"
  9. currentIndex="{{ index }}"
  10. />
  11. <w-pane desc="Line Size = 1" />
  12. <w-tabs lineSize="1" options="{{ tabs1 }}" />
  13. <w-pane desc="Active Color" />
  14. <w-tabs
  15. lineSize="1"
  16. activeColor="#ff8800"
  17. options="{{ tabs3 }}"
  18. />
  19. <w-pane desc="Icon" />
  20. <w-tabs
  21. textStyles="font-size: 14px;"
  22. options="{{ tabs2 }}"
  23. activeColor="#ef473a"
  24. />
  25. <w-pane desc="Disabled Transition and DisabledItem" />
  26. <w-tabs
  27. transition="{{ false }}"
  28. options="{{ tabs4 }}"
  29. bind:disabled="onDisabled"
  30. />
  31. <w-pane desc="Scroll" />
  32. <w-tabs bind:onClick="handleClick" options="{{ tabs5 }}" />
  33. <w-pane desc="Disabled Line" />
  34. <w-tabs
  35. transition="{{ false }}"
  36. line="{{ false }}"
  37. options="{{ tabs4 }}"
  38. />
  39. <w-pane desc="Disabled Border" />
  40. <w-tabs
  41. transition="{{ false }}"
  42. line="{{ false }}"
  43. border="{{ false }}"
  44. options="{{ tabs4 }}"
  45. />
  1. data: {
  2. index: 2,
  3. tabs1: ['电器', '数码', '食品', '手机'],
  4. tabs2: [
  5. {
  6. text: '微博',
  7. icon: 'weibo',
  8. iconSize: '32rpx',
  9. iconColor: '#ef473a',
  10. },
  11. {
  12. text: '脸书',
  13. icon: 'facebook',
  14. iconSize: '32rpx',
  15. iconColor: '#ef473a',
  16. },
  17. {
  18. text: '苹果',
  19. icon: 'apple',
  20. iconSize: '32rpx',
  21. iconColor: '#ef473a',
  22. },
  23. {
  24. text: '安卓',
  25. icon: 'android',
  26. iconSize: '32rpx',
  27. iconColor: '#ef473a',
  28. },
  29. ],
  30. tabs3: [
  31. '英雄联盟',
  32. '绝地求生',
  33. 'DNF',
  34. '炉石传说'
  35. ],
  36. tabs4: [
  37. 'tab1',
  38. 'tab2',
  39. 'tab3',
  40. 'tab4'
  41. ],
  42. tabs5: [
  43. 'tab1',
  44. 'tab2',
  45. 'tab3',
  46. 'tab4',
  47. 'tab5',
  48. 'tab6',
  49. 'tab7',
  50. 'tab8',
  51. 'tab9',
  52. 'tab10'
  53. ],
  54. },
  55. handleChange(e) {
  56. const index = e.detail.index;
  57. console.log(e);
  58. },
  59. handleSelected() {
  60. this.setData({
  61. index: 2,
  62. });
  63. },
  64. handleClick(e) {
  65. const { index, title } = e.detail;
  66. console.log('点击了tab:' + index, title);
  67. },
  68. onDisabled(e) {
  69. const { index, title } = e.detail;
  70. console.log('点击了禁用的:' + index, title);
  71. },
  1. .scroll-view_H {
  2. width: 100%;
  3. white-space: nowrap;
  4. overflow-x: auto;
  5. overflow-y: hidden;
  6. height: 200px;
  7. display: flex;
  8. flex: 1;
  9. justify-content: flex-start;
  10. align-items: center;
  11. flex-direction: row;
  12. flex-wrap: nowrap;
  13. }
  14. .scroll-view-item_H {
  15. width: 50%;
  16. height: 100%;
  17. }
  18. .bc_green {
  19. background-color: green;
  20. }
  21. .bc_red {
  22. background-color: red;
  23. }
  24. .bc_yellow {
  25. background-color: yellow;
  26. }
  27. .bc_blue {
  28. background-color: blue;
  29. }
  30. .content {
  31. padding: 20rpx 40rpx;
  32. }

API

Attribute 属性

属性说明类型默认值
optionstab 列表的数据源 参数有 text,icon,iconColor,iconSizearray[]
currentIndex初始化或者控制索引number0
transition是否开启过渡动画booleanfalse
line是否开启线条booleantrue
duration设置动画时长 单位 snumber0.2
lineSize线条长度大小 0 - 1number0.5
border开启线条stringtrue
borderSize线条粗细 单位 pxstring2
borderColor线条颜色string#eeeeee
activeColor颜色stringrgb(69, 143, 246)
textStyles文本样式string-
fixed是否开启定位booleanfalse

Event 事件

事件名说明参数
onChangetab 变化的时候触发e.detail
disabled禁用的被点击时e.detail

Slot 插槽

名称说明

Class 自定义类名

类名说明
wuss-class根节点样式类