vue全局滚动

176 阅读1分钟
export default {
  mounted() {
    this._initScrollEvent()
  },
  destroyed() {
    window.removeEventListener('scroll', this._scrollEvent)
  },
  methods: {
    _initScrollEvent() {
      window.addEventListener('scroll', this._scrollEvent)
    },
    _scrollEvent(e) {
      const scrollY = window.scrollY
      const viewHeight = window.innerHeight
      const bodyHeight = document.body.scrollHeight
      if (Math.ceil(viewHeight + scrollY) === bodyHeight) {
        this.scrollBottom()
      }
    }
  }
}

import scrollBottom from "@/mixins/scrollBottom"

mixins: [scrollBottom],

// 滚动事件
    scrollBottom(e) {
      this.page += 1
      this.getShopList()
    }