z-paging-swiper-item.vue 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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" style="height: 100%;">
  9. <slot />
  10. </z-paging>
  11. </view>
  12. </template>
  13. <script>
  14. import zPaging from '../z-paging/z-paging'
  15. export default {
  16. name: "z-paging-swiper-item",
  17. components: {
  18. zPaging
  19. },
  20. data() {
  21. return {
  22. firstLoaded: false
  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, oldVal) {
  44. if (newVal === this.tabIndex) {
  45. //懒加载,当滑动到当前的item时,才去加载
  46. if (!this.firstLoaded) {
  47. this.$nextTick(()=>{
  48. let delay = 5;
  49. // #ifdef MP-TOUTIAO
  50. delay = 100;
  51. // #endif
  52. setTimeout(() => {
  53. this.$refs.paging.reload();
  54. }, delay);
  55. })
  56. }
  57. }
  58. },
  59. immediate: true
  60. }
  61. },
  62. methods: {
  63. reload(data) {
  64. this.$refs.paging.reload(data);
  65. },
  66. complete(data) {
  67. this.firstLoaded = true;
  68. this.$refs.paging.complete(data);
  69. },
  70. _queryList(pageNo, pageSize) {
  71. this.$emit('query', pageNo, pageSize);
  72. },
  73. _updateList(list) {
  74. this.$emit('updateList', list);
  75. }
  76. }
  77. }
  78. </script>
  79. <style scoped>
  80. .zp-swiper-item-container {
  81. /* #ifndef APP-NVUE */
  82. height: 100%;
  83. /* #endif */
  84. /* #ifdef APP-NVUE */
  85. flex: 1;
  86. /* #endif */
  87. }
  88. </style>