c-tab


示例

  1. <template>
  2. <page title="c-tab演示">
  3. <view>
  4. <!-- 单tab测试 -->
  5. <view class="title"><text >单tab案例</text></view>
  6. <c-tab tabs="{{tabsAlone}}"
  7. c-bind:tabclick="handleTabTapAlone"
  8. active-label="{{activeLabelAlone}}"
  9. has-underline="{{false}}"
  10. inline="{{false}}"
  11. >
  12. </c-tab>
  13. <view class="title"><text class="title">tab+pane案例</text></view>
  14. <c-tab tabs="{{tabs}}"
  15. c-bind:tabclick="handleTabTap"
  16. active-label="{{activeLabel}}"
  17. inline="{{false}}"
  18. >
  19. </c-tab>
  20. <c-tab-pane tabs="{{tabs}}" active-label="{{activeLabel}}">
  21. <!-- 案例1 -->
  22. <!-- <c-tab-pane-item c-for="{{tabs}}" >
  23. <slot><text>{{item.label}}</text></slot>
  24. </c-tab-pane-item> -->
  25. <!-- 案例2 -->
  26. <c-tab-pane-item>
  27. <view class="one"><text>
  28. 1
  29. </text></view>
  30. </c-tab-pane-item>
  31. <c-tab-pane-item>
  32. <view class="two"><text>
  33. 2
  34. </text></view>
  35. </c-tab-pane-item>
  36. <c-tab-pane-item>
  37. <view class="three"><text>
  38. 3
  39. </text></view>
  40. </c-tab-pane-item>
  41. <c-tab-pane-item>
  42. <view><text>
  43. 4
  44. </text></view>
  45. </c-tab-pane-item>
  46. </c-tab-pane>
  47. </view>
  48. </page>
  49. </template>
  50. <script>
  51. /***
  52. * prefixStyle suffixStyle 可以用来放置图标
  53. */
  54. class CTab {
  55. data = {
  56. headerTitle: 'c-tabs',
  57. headerDesc: 'c-tabs',
  58. tabsAlone:[{
  59. label:'label11',
  60. // prefixStyle:"width:50cpx;height:20cpx;background-color:red;",
  61. },{
  62. label:"label22",
  63. // suffixStyle:"width:50cpx;height:20cpx;background-color:red;"
  64. },{
  65. label:'label33',
  66. }],
  67. activeLabelAlone:'label33',
  68. tabs:[{
  69. label:'label1',
  70. // prefixStyle:"width:50cpx;height:20cpx;background-color:red"
  71. },{
  72. label:"label2",
  73. // suffixStyle:"width:50cpx;height:20cpx;background-color:red"
  74. },{
  75. label:'label3',
  76. // labelStyle:"color:green"
  77. }],
  78. activeLabel:'label3',
  79. }
  80. methods = {
  81. handleTabTap(e){
  82. console.log(e);
  83. this.activeLabel = e.detail.label;
  84. },
  85. handleTabTapAlone(e){
  86. this.activeLabelAlone = e.detail.label;
  87. }
  88. }
  89. }
  90. export default new CTab();
  91. </script>
  92. <script cml-type="json">
  93. {
  94. "base":{
  95. "usingComponents": {
  96. "c-tab": "cml-ui/components/c-tab/c-tab",
  97. "c-tab-pane": "cml-ui/components/c-tab-pane/c-tab-pane",
  98. "c-tab-pane-item": "cml-ui/components/c-tab-pane-item/c-tab-pane-item"
  99. }
  100. }
  101. }
  102. </script>
  103. <style scoped>
  104. .container {
  105. flex: 1;
  106. background: #f8f8f8;
  107. }
  108. .title{
  109. display:flex;
  110. flex-direction:row;
  111. justify-content:center;
  112. line-height: 88cpx;
  113. font-size: 28cpx;
  114. text-align: center;
  115. height: 88cpx;
  116. color: #999;
  117. }
  118. .one{
  119. color:#fff;
  120. height:500cpx;
  121. background-color:rgb(46, 240, 127);
  122. }
  123. .two{
  124. color:#fff;
  125. height:500cpx;
  126. background-color:rgb(0, 162, 255);
  127. }
  128. .three{
  129. color:#fff;
  130. height:500cpx;
  131. background-color:#00ffe4;
  132. }
  133. </style>

c-tab  - 图1wx

c-tab  - 图2web

c-tab  - 图3native