swiper-list-view.uvue 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. <template>
  2. <view style="flex: 1;">
  3. <view class="content-item">
  4. <text class="text">左右滑动页面,体验swiper嵌套list-view效果。</text>
  5. </view>
  6. <swiper style="flex: 1;" :current="currentVal" @change="swiperChange">
  7. <swiper-item v-for="index in 3">
  8. <list-view :id="'list'+index" style="flex: 1;" refresher-enabled="true" @refresherrefresh="onRefresherrefresh"
  9. :refresher-triggered="refresherTriggeredArray[index-1]" :scroll-top="scrollTop">
  10. <sticky-header>
  11. <text class="header">上下滑动体验吸顶效果 swiper-item{{index}}</text>
  12. </sticky-header>
  13. <list-item v-for="itemIndex in 40" class="item">
  14. <text>item----------{{itemIndex}}</text>
  15. </list-item>
  16. </list-view>
  17. </swiper-item>
  18. </swiper>
  19. </view>
  20. </template>
  21. <script>
  22. export default {
  23. data() {
  24. return {
  25. swiperCurrentIndex: 0,
  26. currentVal: 0,
  27. scrollTop: 0,
  28. refresherTriggeredArray: [false, false, false] as Array<boolean>,
  29. }
  30. },
  31. methods: {
  32. swiperChange(e : SwiperChangeEvent) {
  33. this.swiperCurrentIndex = e.detail.current
  34. },
  35. onRefresherrefresh() {
  36. this.refresherTriggeredArray[this.swiperCurrentIndex] = true;
  37. setTimeout(() => {
  38. this.refresherTriggeredArray[this.swiperCurrentIndex] = false;
  39. }, 100)
  40. }
  41. }
  42. }
  43. </script>
  44. <style>
  45. .item {
  46. padding: 15px;
  47. margin: 0 0 5px 0;
  48. background-color: #fff;
  49. border-radius: 5px;
  50. }
  51. .text {
  52. font-size: 14px;
  53. color: #666;
  54. line-height: 20px;
  55. }
  56. .content-item {
  57. padding: 15px;
  58. margin-bottom: 10px;
  59. background-color: #fff;
  60. }
  61. .header {
  62. background-color: #ffaa00;
  63. padding: 15px;
  64. text-align: center;
  65. color: #fff;
  66. }
  67. </style>