PullUp.vue 1.5 KB

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