uni-recycle-item.uvue 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. <template>
  2. <view class="uni-recycle-view-item" :style="this.itemHeight != 0 ? {height: this.itemHeight + 'px'} : {}">
  3. <slot></slot>
  4. </view>
  5. </template>
  6. <script>
  7. /**
  8. * recycle-item 长列表子项组件
  9. * @description 用于展示超长列表数据每一项
  10. * @property {any[]} item 当前组件渲染的列表项
  11. */
  12. export default {
  13. name: "uni-recycle-item",
  14. props: {
  15. item: {
  16. type: Object as PropType<any>,
  17. required: true
  18. }
  19. },
  20. inject: {
  21. itemHeight: {
  22. type: Number as PropType<number>
  23. },
  24. setCachedSize: {
  25. type: Function as PropType<(item : any, size : number) => void>
  26. },
  27. getCachedSize: {
  28. type: Function as PropType<(item : any) => number | null>
  29. },
  30. },
  31. mounted() {
  32. if (this.itemHeight == 0) {
  33. const cachedSize = this.getCachedSize(this.item)
  34. if(cachedSize == null) {
  35. this.$nextTick(() => {
  36. uni.createSelectorQuery().in(this).select('.uni-recycle-view-item').boundingClientRect().exec((ret) => {
  37. this.setCachedSize(this.item, (ret[0] as NodeInfo).height!)
  38. })
  39. })
  40. }
  41. }
  42. }
  43. }
  44. </script>
  45. <style>
  46. .uni-recycle-view-item {
  47. box-sizing: border-box;
  48. overflow: hidden;
  49. }
  50. </style>