PullDown.vue 1.2 KB

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