z-paging-swiper-item.vue 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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. this.$nextTick(()=>{
  49. setTimeout(() => {
  50. this.$refs.paging.reload();
  51. }, 5);
  52. })
  53. }
  54. }
  55. },
  56. immediate: true
  57. }
  58. },
  59. methods: {
  60. reload(data) {
  61. this.$refs.paging.reload(data);
  62. },
  63. complete(data) {
  64. this.firstLoaded = true;
  65. this.$refs.paging.complete(data);
  66. },
  67. _queryList(pageNo, pageSize) {
  68. this.$emit('query', pageNo, pageSize);
  69. },
  70. _updateList(list) {
  71. this.$emit('updateList', list);
  72. }
  73. }
  74. }
  75. </script>
  76. <style scoped>
  77. .zp-swiper-item-container {
  78. /* #ifndef APP-NVUE */
  79. height: 100%;
  80. /* #endif */
  81. /* #ifdef APP-NVUE */
  82. flex: 1;
  83. /* #endif */
  84. }
  85. </style>