u-refresh-virtual-list.vue 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. <template>
  2. <u-pull-refresh
  3. :refreshing="refreshing"
  4. :threshold="50"
  5. @refresh="handleRefresh"
  6. >
  7. <u-virtual-list
  8. ref="virtualList"
  9. :list-data="listData"
  10. :item-height="itemHeight"
  11. :height="height"
  12. :buffer="buffer"
  13. :key-field="keyField"
  14. :scroll-top="scrollTop"
  15. @scroll="handleScroll"
  16. >
  17. <template #default="{ item, index }">
  18. <slot :item="item" :index="index"></slot>
  19. </template>
  20. </u-virtual-list>
  21. </u-pull-refresh>
  22. </template>
  23. <script>
  24. export default {
  25. name: 'u-refresh-virtual-list',
  26. props: {
  27. // 数据源
  28. listData: {
  29. type: Array,
  30. default: () => []
  31. },
  32. // 每项高度(固定高度模式)
  33. itemHeight: {
  34. type: Number,
  35. default: 50
  36. },
  37. // 容器高度
  38. height: {
  39. type: [String, Number],
  40. default: '100%'
  41. },
  42. // 缓冲区项数
  43. buffer: {
  44. type: Number,
  45. default: 4
  46. },
  47. // 索引键名
  48. keyField: {
  49. type: String,
  50. default: 'id'
  51. }
  52. },
  53. data() {
  54. return {
  55. refreshing: false,
  56. scrollTop: 0
  57. }
  58. },
  59. methods: {
  60. handleRefresh() {
  61. this.refreshing = true
  62. this.$emit('refresh')
  63. },
  64. handleScroll(scrollTop) {
  65. this.scrollTop = scrollTop
  66. this.$emit('scroll', scrollTop)
  67. },
  68. finishRefresh() {
  69. this.refreshing = false
  70. },
  71. scrollTo(top) {
  72. this.scrollTop = top
  73. },
  74. scrollToTop() {
  75. this.scrollTo(0)
  76. }
  77. }
  78. }
  79. </script>