z-paging-swiper-item.vue 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. <!-- z-paging -->
  2. <!-- github地址:https://github.com/SmileZXLee/uni-z-paging -->
  3. <!-- dcloud地址:https://ext.dcloud.net.cn/plugin?id=3935 -->
  4. <!-- 反馈QQ群:790460711 -->
  5. <!-- 滑动切换选项卡swiper-item,此组件支持easycom规范,可以在项目中直接引用 -->
  6. <template>
  7. <view class="zp-swiper-item-container">
  8. <z-paging ref="paging" :fixed="false" @query="_queryList" @listChange="_updateList" :mounted-auto-call-reload="false"
  9. style="height: 100%;">
  10. <slot></slot>
  11. </z-paging>
  12. </view>
  13. </template>
  14. <script>
  15. import zPaging from '../z-paging/z-paging'
  16. export default {
  17. name: "z-paging-swiper-item",
  18. components: {
  19. zPaging
  20. },
  21. data() {
  22. return {
  23. firstLoaded: false
  24. }
  25. },
  26. props: {
  27. //当前组件的index,也就是当前组件是swiper中的第几个
  28. tabIndex: {
  29. type: Number,
  30. default: function() {
  31. return 0
  32. }
  33. },
  34. //当前swiper切换到第几个index
  35. currentIndex: {
  36. type: Number,
  37. default: function() {
  38. return 0
  39. }
  40. },
  41. },
  42. watch: {
  43. currentIndex: {
  44. handler(newVal, oldVal) {
  45. if (newVal === this.tabIndex) {
  46. //懒加载,当滑动到当前的item时,才去加载
  47. if (!this.firstLoaded) {
  48. setTimeout(() => {
  49. this.$refs.paging.reload();
  50. }, 5);
  51. }
  52. }
  53. },
  54. immediate: true
  55. }
  56. },
  57. methods: {
  58. reload(data) {
  59. this.$refs.paging.reload(data);
  60. },
  61. complete(data) {
  62. this.firstLoaded = true;
  63. this.$refs.paging.complete(data);
  64. },
  65. _queryList(pageNo, pageSize) {
  66. this.$emit('query', pageNo, pageSize);
  67. },
  68. _updateList(list) {
  69. this.$emit('updateList', list);
  70. }
  71. }
  72. }
  73. </script>
  74. <style scoped>
  75. .zp-swiper-item-container {
  76. /* #ifndef APP-NVUE */
  77. height: 100%;
  78. /* #endif */
  79. /* #ifdef APP-NVUE */
  80. flex: 1;
  81. /* #endif */
  82. }
  83. </style>