index.vue 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217
  1. <template>
  2. <demo-section>
  3. <demo-block :title="$t('basicUsage')">
  4. <van-tabs v-model="active">
  5. <van-tab
  6. :title="$t('tab') + index"
  7. v-for="index in tabs"
  8. :key="index"
  9. >
  10. {{ $t('content') }} {{ index }}
  11. </van-tab>
  12. </van-tabs>
  13. </demo-block>
  14. <demo-block :title="$t('title2')">
  15. <van-tabs @scroll="onScroll">
  16. <van-tab
  17. v-for="index in 8"
  18. :title="$t('tab') + index"
  19. :key="index"
  20. >
  21. {{ $t('content') }} {{ index }}
  22. </van-tab>
  23. </van-tabs>
  24. </demo-block>
  25. <demo-block :title="$t('title3')">
  26. <van-tabs @disabled="onClickDisabled">
  27. <van-tab
  28. v-for="index in 3"
  29. :title="$t('tab') + index"
  30. :disabled="index === 2"
  31. :key="index"
  32. >
  33. {{ $t('content') }} {{ index }}
  34. </van-tab>
  35. </van-tabs>
  36. </demo-block>
  37. <demo-block :title="$t('title4')">
  38. <van-tabs type="card">
  39. <van-tab
  40. v-for="index in 3"
  41. :title="$t('tab') + index"
  42. :key="index"
  43. >
  44. {{ $t('content') }} {{ index }}
  45. </van-tab>
  46. </van-tabs>
  47. </demo-block>
  48. <demo-block :title="$t('title5')">
  49. <van-tabs @click="onClick">
  50. <van-tab
  51. v-for="index in 2"
  52. :title="$t('tab') + index"
  53. :key="index"
  54. >
  55. {{ $t('content') }} {{ index }}
  56. </van-tab>
  57. </van-tabs>
  58. </demo-block>
  59. <demo-block :title="$t('title6')">
  60. <van-tabs
  61. :active="active"
  62. sticky
  63. >
  64. <van-tab
  65. :title="$t('tab') + index"
  66. v-for="index in tabs"
  67. :key="index"
  68. >
  69. {{ $t('content') }} {{ index }}
  70. </van-tab>
  71. </van-tabs>
  72. </demo-block>
  73. <demo-block :title="$t('title7')">
  74. <van-tabs :active="active">
  75. <van-tab
  76. v-for="index in 2"
  77. :key="index"
  78. >
  79. <div slot="title">
  80. <van-icon name="more-o" />{{ $t('tab') }}
  81. </div>
  82. {{ $t('content') }} {{ index }}
  83. </van-tab>
  84. </van-tabs>
  85. </demo-block>
  86. <demo-block :title="$t('title8')">
  87. <van-tabs
  88. animated
  89. >
  90. <van-tab
  91. :title="$t('tab') + index"
  92. v-for="index in tabs"
  93. :key="index"
  94. >
  95. {{ $t('content') }} {{ index }}
  96. </van-tab>
  97. </van-tabs>
  98. </demo-block>
  99. <demo-block :title="$t('title9')">
  100. <van-tabs
  101. :active="active"
  102. swipeable
  103. >
  104. <van-tab
  105. :title="$t('tab') + index"
  106. v-for="index in tabs"
  107. :key="index"
  108. >
  109. {{ $t('content') }} {{ index }}
  110. </van-tab>
  111. </van-tabs>
  112. </demo-block>
  113. </demo-section>
  114. </template>
  115. <script>
  116. export default {
  117. i18n: {
  118. 'zh-CN': {
  119. tab: '标签 ',
  120. title2: '横向滚动',
  121. title3: '禁用标签',
  122. title4: '样式风格',
  123. title5: '点击事件',
  124. title6: '粘性布局',
  125. title7: '自定义标签',
  126. title8: '切换动画',
  127. title9: '滑动切换',
  128. disabled: ' 已被禁用'
  129. },
  130. 'en-US': {
  131. tab: 'Tab ',
  132. content: 'content of tab',
  133. title2: 'Swipe Tabs',
  134. title3: 'Disabled Tab',
  135. title4: 'Card Style',
  136. title5: 'Click Event',
  137. title6: 'Sticky',
  138. title7: 'Custom Tab',
  139. title8: 'Switch Animation',
  140. title9: 'Swipeable',
  141. disabled: ' is disabled'
  142. }
  143. },
  144. data() {
  145. return {
  146. active: 2,
  147. tabs: [1, 2, 3, 4]
  148. };
  149. },
  150. methods: {
  151. onClickDisabled(index, title) {
  152. this.$toast(title + this.$t('disabled'));
  153. },
  154. onClick(index, title) {
  155. this.$toast(title);
  156. },
  157. onScroll(e) {
  158. console.log(e);
  159. }
  160. }
  161. };
  162. </script>
  163. <style lang="less">
  164. @import '../../style/var';
  165. .demo-tab {
  166. margin-bottom: 300px;
  167. .van-tab .van-icon {
  168. margin-right: 5px;
  169. vertical-align: -2px;
  170. }
  171. .van-tab__pane {
  172. background-color: @white;
  173. padding: 20px;
  174. }
  175. .van-tabs--card .van-tab__pane {
  176. background-color: transparent;
  177. }
  178. .custom-tabwrap .van-tab-active {
  179. color: #20a0ff;
  180. }
  181. .custom-tabwrap .van-tabs-nav-bar {
  182. background: #20a0ff;
  183. }
  184. .custom-pane {
  185. text-align: center;
  186. height: 50px;
  187. line-height: 50px;
  188. }
  189. .van-doc-demo-block:last-child {
  190. .van-tab__pane {
  191. padding: 50px 20px;
  192. }
  193. }
  194. }
  195. </style>