You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

87 regels
1.6 KiB

  1. <template>
  2. <scroll-view
  3. @scrolltolower="$emit('toBottom')"
  4. @refresherrefresh="onRefresh"
  5. @refresherrestore="onRefreshRestore"
  6. @scroll="scroll"
  7. :scroll-top="scrollTop"
  8. :refresher-triggered="pullDown"
  9. :refresher-enabled="enablePullDown"
  10. :refresher-background="refresherBackground"
  11. :refresher-threshold="80"
  12. class="lr-scroll-list"
  13. style="height: 100%; display: block;"
  14. scroll-anchoring
  15. scroll-y
  16. >
  17. <slot></slot>
  18. </scroll-view>
  19. </template>
  20. <script>
  21. export default {
  22. name: 'l-scroll-list',
  23. props: {
  24. refresherBackground: { default: '#f3f3f3' }
  25. },
  26. data() {
  27. return {
  28. scrollTop: 0,
  29. pullDown: true,
  30. enablePullDown: true
  31. }
  32. },
  33. methods: {
  34. // 【外部调用的方法】,滚动到某个高度
  35. scrollTo(num) {
  36. this.$nextTick(() => {
  37. this.scrollTop = num
  38. })
  39. },
  40. // 【外部调用的方法】,结束下拉刷新
  41. stopPullDown() {
  42. this.pullDown = false
  43. this.isPullDown = false
  44. },
  45. // 下拉刷新触发
  46. onRefresh() {
  47. if (this.isPullDown) {
  48. return
  49. }
  50. this.isPullDown = true
  51. this.pullDown = true
  52. this.$emit('pullDown')
  53. },
  54. // 下拉恢复可用
  55. onRefreshRestore() {
  56. this.pullDown = false
  57. this.isPullDown = false
  58. },
  59. // 列表滚动时
  60. scroll(e) {
  61. // 修复 App 和 H5 端的滚动过快
  62. // #ifdef APP-VUE || H5
  63. this.enablePullDown = e.detail.scrollTop <= 0
  64. // #endif
  65. this.$emit('scroll', e)
  66. }
  67. }
  68. }
  69. </script>
  70. <style lang="less">
  71. :host {
  72. display: block;
  73. height: 100vh;
  74. }
  75. </style>