swiper-item-list.vue 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. <template>
  2. <view class="content">
  3. <z-paging v-if="firstLoaded || isCurrentPage" ref="paging" class="paging" @query="queryList" :fixed="false"
  4. auto-show-back-to-top back-to-top-img="../../static/icon/icon-3.png"
  5. :back-to-top-style="{width:'80rpx',height:'80rpx',backgroundColor:'#333333',borderRadius:'40rpx',padding:'20rpx',}"
  6. :loading-more-custom-style="{height:'60px',paddingBottom:'30px'}">
  7. <slot></slot>
  8. </z-paging>
  9. </view>
  10. </template>
  11. </template>
  12. <script>
  13. export default {
  14. name: "swiper-item-list",
  15. data() {
  16. return {
  17. // 当前组件是否已经加载过了
  18. firstLoaded: false,
  19. // 是否滚动到当前页
  20. isCurrentPage: false,
  21. current: 0,
  22. dataList: [],
  23. };
  24. },
  25. props: {
  26. // 当前组件的index,也就是当前组件是swiper中的第几个
  27. tabIndex: {
  28. type: Number,
  29. default: function() {
  30. return 0
  31. }
  32. },
  33. // 当前swiper切换到第几个index
  34. currentIndex: {
  35. type: Number,
  36. default: function() {
  37. return 0
  38. }
  39. }
  40. },
  41. watch: {
  42. currentIndex: {
  43. handler(newVal) {
  44. if (newVal === this.tabIndex) {
  45. // 懒加载,当滑动到当前的item时,才去加载
  46. if (!this.firstLoaded) {
  47. // 这里需要延迟渲染z-paging的原因是为了避免在一些平台上立即渲染可能引发的底层报错问题
  48. this.$nextTick(() => {
  49. this.isCurrentPage = true;
  50. })
  51. }
  52. }
  53. },
  54. immediate: true
  55. },
  56. },
  57. methods: {
  58. queryList(pageNo, pageSize) {
  59. this.current = pageNo;
  60. const params = {
  61. pageNo: pageNo,
  62. pageSize: pageSize,
  63. type: this.tabIndex,
  64. complete: (data) => {
  65. this.$refs.paging.complete(data);
  66. if (!data) return [];
  67. return data
  68. }
  69. }
  70. this.$emit('query', params)
  71. },
  72. // 接收父组件传过来的刷新列表要求
  73. reload() {
  74. // 刷新列表数据(如果不希望列表pageNo被重置可以用refresh代替reload方法)
  75. this.$refs.paging && this.$refs.paging.reload();
  76. },
  77. }
  78. }
  79. </script>
  80. <style lang="scss">
  81. .content {
  82. flex: 1;
  83. /* #ifndef APP-NVUE */
  84. height: 100%;
  85. /* #endif */
  86. }
  87. .paging {
  88. /* #ifndef APP-NVUE */
  89. height: 100%;
  90. /* #endif */
  91. }
  92. </style>