PullUp.vue 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. <template>
  2. <!-- 移动端上拉加载更多 -->
  3. </template>
  4. <script>
  5. export default {
  6. props: {
  7. searchMore: {
  8. type: Boolean
  9. },
  10. allPage: {
  11. type: Number
  12. },
  13. page: {
  14. type: Number
  15. },
  16. fixId: {
  17. type: String,
  18. default: null
  19. },
  20. isValid: {
  21. type: Boolean,
  22. default: true
  23. }
  24. },
  25. mounted () {
  26. let _this = this
  27. _this.$nextTick(function () {
  28. let obj = this.fixId ? document.getElementById(this.fixId) : window
  29. obj.addEventListener('scroll', function () {
  30. if (_this.isValid) {
  31. _this.scroll()
  32. }
  33. }, false)
  34. })
  35. },
  36. methods: {
  37. scroll: function () {
  38. let scrolled = 0
  39. let height = 0
  40. // console.log(document.getElementById(this.fixId).scrollHeight)
  41. // console.log(document.getElementById(this.fixId).scrollTop + window.screen.availHeight + '-------')
  42. if (this.fixId) {
  43. let obj = document.getElementById(this.fixId)
  44. height = obj.scrollHeight
  45. scrolled = obj.scrollTop - 88
  46. } else {
  47. height = document.body.scrollHeight
  48. scrolled = document.documentElement.scrollTop || window.pageYOffset || document.body.scrollTop
  49. }
  50. if (Math.ceil(scrolled + window.screen.availHeight) >= height && !this.searchMore && this.page < this.allPage) {
  51. this.getMore()
  52. }
  53. },
  54. getMore: function () {
  55. if (!this.searchMore) {
  56. this.$emit('pullUpAction')
  57. }
  58. }
  59. }
  60. }
  61. </script>
  62. <style lang="scss" scoped>
  63. .loading {
  64. text-align: center;
  65. background: #fff;
  66. >img {
  67. width: .64rem;
  68. height: .64rem;
  69. margin: .2rem 0;
  70. }
  71. }
  72. </style>