loadMore.js 541 B

123456789101112131415161718
  1. // directives.js
  2. import Vue from 'vue'
  3. const loadmore = Vue.directive('loadmore', {
  4. bind (el, binding) {
  5. const scrollWrap = el.querySelector('.el-select-dropdown__wrap')
  6. scrollWrap.addEventListener('scroll', function () {
  7. // 解决浏览器缩放导致的 scrollTop 小数问题
  8. const isBottom =
  9. this.scrollHeight - Math.ceil(this.scrollTop) <= this.clientHeight + 1
  10. if (isBottom && this.scrollTop !== 0) {
  11. binding.value() // 触发加载函数
  12. }
  13. })
  14. }
  15. })
  16. export default { loadmore }