demo.vue 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. <template>
  2. <view>
  3. <view class="p10">普通使用</view>
  4. <sun-tab :value.sync="index" :tabList="tabList"></sun-tab>
  5. <view class="p10">更换颜色</view>
  6. <sun-tab :value.sync="index" @change="arrayChange" :tabList="tabColorList" activeColor="#f37b1d" defaultColor="#FFFFFF" bgColor="#1e9fff"></sun-tab>
  7. <view class="p10">使用icon</view>
  8. <sun-tab :value.sync="index" :tabList="tabIconList" rangeKey="name"></sun-tab>
  9. <view class="p10">对象赋值</view>
  10. <sun-tab :value.sync="index" @change="objectChange" :tabList="tabObjectList" rangeKey="name"></sun-tab>
  11. <view class="p10">横向滚动</view>
  12. <sun-tab :value.sync="tabScrollIndex" :tabList="tabScrollList" :scroll="true"></sun-tab>
  13. <view class="p10">搭配滑块使用</view>
  14. <sun-tab :value.sync="swiperIndex" :tabList="tabSwiperList"></sun-tab>
  15. <swiper :current="swiperIndex" duration="300" :circular="true" indicator-color="rgba(255,255,255,0)" indicator-active-color="rgba(255,255,255,0)" @change="swiperChange">
  16. <swiper-item v-for="(swiper,index) in tabSwiperList" :key="index">
  17. <view style="margin: 20px;background-color: #FFFFFF;text-align: center;">{{swiper}}</view>
  18. </swiper-item>
  19. </swiper>
  20. </view>
  21. </template>
  22. <script>
  23. import sunTab from '@/components/sun-tab/sun-tab.vue';
  24. export default {
  25. components: {
  26. sunTab
  27. },
  28. data() {
  29. return {
  30. index: 0,
  31. swiperIndex:0,
  32. tabList: ['选项卡一','选项卡二','选项卡三'],
  33. tabColorList: ['选项卡一','选项卡二','选项卡三选项卡三项卡三'],
  34. tabIconList: [
  35. {
  36. name: '男',
  37. icon: 'iconnan',
  38. },
  39. {
  40. name: '女',
  41. icon: 'iconziyuan',
  42. },
  43. {
  44. name: '儿童',
  45. icon: 'icon10',
  46. }
  47. ],
  48. tabObjectList: [
  49. {
  50. name: '选项卡一',
  51. value: 1
  52. },
  53. {
  54. name: '选项卡二',
  55. value: 2
  56. },
  57. {
  58. name: '选项卡三',
  59. value: 3
  60. }
  61. ],
  62. tabScrollIndex: 0,
  63. tabScrollList: ['选项卡一','选项卡二选项卡二','选项卡三','选项卡四','选项卡五选项卡五选项卡五','选项卡六','选项卡七','选项卡八'],
  64. tabSwiperList: ['A','B','C'],
  65. }
  66. },
  67. onLoad() {
  68. },
  69. methods: {
  70. arrayChange(e){
  71. console.log('数组数据返回格式');
  72. console.log(e);
  73. },
  74. objectChange(e){
  75. console.log('对象数据返回格式');
  76. console.log(e);
  77. },
  78. swiperChange(e){
  79. this.swiperIndex = e.target.current;
  80. }
  81. }
  82. }
  83. </script>
  84. <style lang="scss">
  85. uni-page-body{
  86. background-color: #f4f4f4;
  87. }
  88. .p10{
  89. padding: 10px;
  90. font-size: 16px;
  91. }
  92. </style>