kTabsSwiper.vue 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. <template>
  2. <view class="kTabsSwiper">
  3. <k-tabs-swiper
  4. v-model="current"
  5. :tabs="tabs"
  6. :tabsSwiper="true"
  7. bgColor="#1EBB81"
  8. color="rgba(255,255,255,0.8)"
  9. activeColor="#FFFFFF"
  10. fontSize="28rpx"
  11. lineColor="#FFFFFF"
  12. :bold="true"
  13. :scroll="true"
  14. :fixed="true"
  15. height="100rpx"
  16. lineHeight="10rpx"
  17. @change="changeTab"
  18. @load="load"
  19. paddingItem="0 50rpx"
  20. >
  21. <template slot="swiperContent" slot-scope="{index}">
  22. <view class="item" :class="{
  23. 'item-active': itemIndex % 2
  24. }" v-for="(item,itemIndex) in tabsLists[index]" :key="itemIndex">
  25. <text>{{index}}+{{itemIndex}}</text>
  26. </view>
  27. <view class="loading">触发到底部</view>
  28. </template>
  29. </k-tabs-swiper>
  30. </view>
  31. </template>
  32. <script>
  33. import KTabsSwiper from '../k-tabs-swiper/k-tabs-swiper'
  34. export default{
  35. components:{
  36. KTabsSwiper
  37. },
  38. data() {
  39. return {
  40. current: 0,
  41. tabs:['新闻', '早报', '军事', '生活', '地区事件', '文化', '军事', '国内', '新闻'],
  42. tabsLists:[],
  43. isListFinished: [],
  44. }
  45. },
  46. onLoad(options) {
  47. this.init();
  48. },
  49. methods: {
  50. //此为测试用方法
  51. init(){
  52. this.tabsLists = new Array(this.tabs.length).fill([]);
  53. this.tabs.forEach((item,index) => {
  54. this.isListFinished.push({
  55. canLoad:true,
  56. pageNum:0,
  57. pageSize:20
  58. });
  59. })
  60. this.changeTab(0);
  61. },
  62. getData(index){
  63. let newArr = new Array(20).fill([]);
  64. this.$set(this.tabsLists,index,this.tabsLists[index].concat(newArr))
  65. },
  66. load(index){
  67. this.isListFinished[index].pageNum++;
  68. uni.showToast({
  69. title: `第${index}个触发底部,页码${this.isListFinished[index].pageNum}`,
  70. icon: 'none',
  71. })
  72. this.getData(index)
  73. },
  74. changeTab(index){
  75. uni.showToast({
  76. title: `第${index}个`,
  77. icon: 'none',
  78. })
  79. this.getData(index)
  80. }
  81. },
  82. }
  83. </script>
  84. <style lang="scss" scoped>
  85. .title{
  86. font-weight: bold;
  87. padding: 16rpx;
  88. }
  89. .line_img{
  90. width: 42rpx;
  91. height: 17rpx;
  92. }
  93. .item{
  94. display: flex;
  95. justify-content: center;
  96. align-items: center;
  97. height: 100rpx;
  98. }
  99. .item-active{
  100. background: rgb(30, 187, 129);
  101. }
  102. .loading{
  103. text-align: center;
  104. padding: 20rpx 0;
  105. }
  106. </style>