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