index.vue 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. <template>
  2. <view class="u-demo">
  3. <view class="u-demo-wrap">
  4. <view class="u-demo-title">演示效果</view>
  5. <view class="u-demo-area">
  6. <u-toast ref="uToast"></u-toast>
  7. <u-tabs v-if="control" bg-color="#fafafa" :bold="bold" :active-color="activeColor" :list="list"
  8. @change="change" :current="current" :is-scroll="isScroll" :offset="offset"></u-tabs>
  9. </view>
  10. </view>
  11. <view class="u-config-wrap">
  12. <view class="u-config-title u-border-bottom">
  13. 参数配置
  14. </view>
  15. <view class="u-config-item">
  16. <view class="u-item-title">模式选择</view>
  17. <u-subsection :current="sectionCurrent" :list="['滚动', '非滚动']" @change="modeChange"></u-subsection>
  18. </view>
  19. <view class="u-config-item">
  20. <view class="u-item-title">标签个数(非滚动模式)</view>
  21. <u-subsection :list="['2', '3', '4']" @change="countChange"></u-subsection>
  22. </view>
  23. <view class="u-config-item">
  24. <view class="u-item-title">活动选项字颜色</view>
  25. <u-subsection mode="button" :list="['primary', 'success', 'error', 'warning']" @change="colorChange"></u-subsection>
  26. </view>
  27. <view class="u-config-item">
  28. <view class="u-item-title">字体加粗</view>
  29. <u-subsection mode="button" :list="['是', '否']" @change="boldChange"></u-subsection>
  30. </view>
  31. </view>
  32. </view>
  33. </template>
  34. <script>
  35. export default {
  36. data() {
  37. return {
  38. list: [],
  39. data: [{
  40. name: '关注',
  41. count: 100
  42. }, {
  43. name: '推荐',
  44. count: 7
  45. }, {
  46. name: '电影'
  47. },{
  48. name: '电视剧'
  49. },{
  50. name: '小视频'
  51. }, {
  52. name: '游戏'
  53. }, {
  54. name: '校园'
  55. },{
  56. name: '影视'
  57. },{
  58. name: '音乐'
  59. }],
  60. current: 0,
  61. sectionCurrent: 0,
  62. isScroll: true,
  63. tabCountIndex: 0,
  64. activeColor: this.$u.color['primary'],
  65. bold: true,
  66. control: true,
  67. offset: [5, -5]
  68. }
  69. },
  70. onLoad() {
  71. this.list = this.data;
  72. },
  73. methods: {
  74. countChange(index) {
  75. this.sectionCurrent = 1;
  76. if(index == 0) {
  77. this.list = [];
  78. this.list.push(this.data[0]);
  79. this.list.push(this.data[1]);
  80. this.offset = [5, 60]
  81. } else if(index == 1) {
  82. this.list = [];
  83. this.list.push(this.data[0]);
  84. this.list.push(this.data[1]);
  85. this.list.push(this.data[2]);
  86. this.offset = [5, 20]
  87. } else {
  88. this.list = [];
  89. this.list.push(this.data[0]);
  90. this.list.push(this.data[1]);
  91. this.list.push(this.data[2]);
  92. this.list.push(this.data[3]);
  93. this.offset = [5, 5]
  94. }
  95. this.tabCountIndex = index;
  96. this.isScroll = false;
  97. },
  98. change(index) {
  99. this.current = index;
  100. },
  101. modeChange(index) {
  102. this.control = false;
  103. this.current = 0;
  104. if(index == 0) {
  105. this.isScroll = true;
  106. this.list = this.data;
  107. this.offset = [5, -5]
  108. } else {
  109. this.isScroll = false;
  110. this.countChange(this.tabCountIndex);
  111. }
  112. this.$nextTick(() => {
  113. this.control = true;
  114. })
  115. },
  116. colorChange(e) {
  117. let color = 'primary';
  118. switch(e) {
  119. case 0:
  120. color = 'primary';break;
  121. case 1:
  122. color = 'success';break;
  123. case 2:
  124. color = 'error';break;
  125. case 3:
  126. color = 'warning';break;
  127. }
  128. this.activeColor = this.$u.color[color];
  129. },
  130. boldChange(e) {
  131. switch(e) {
  132. case 0:
  133. this.bold = true;break;
  134. case 1:
  135. this.bold = false;break;
  136. }
  137. }
  138. }
  139. }
  140. </script>
  141. <style lang="scss" scoped>
  142. .u-config-wrap {
  143. }
  144. </style>