PullUp.vue 1.2 KB

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