el-select上拉加载数据

el-select上拉加载数据,第1张

一、注册指令并在main.js引入

import Vue from 'vue'

var timer = ''
Vue.directive('loadmore', {
    bind(el, binding) {
    // 获取element-ui定义好的scroll盒子
      const SELECTWRAP_DOM = el.querySelector('.el-select-dropdown .el-select-dropdown__wrap')
      if (SELECTWRAP_DOM) {
        SELECTWRAP_DOM.addEventListener('scroll', function() {
          // + 10 : 防止浏览器有时候不触底
          const CONDITION = this.scrollHeight - this.scrollTop <= this.clientHeight + 10
          if (CONDITION) {
            if (timer) {
              clearTimeout(timer)
            }
            timer = setTimeout(() => {
              binding.value()
            }, 100)
          }
        })
      }
    }
  })

二、使用 

三、方法 


methods: {
    // 加载更多
    loadMore() {
      console.log('加载跟多')
      this.page += 1
      if (this.page <= this.total) {
        this.getList()
      }
    }
}

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/web/1320827.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-06-11
下一篇 2022-06-11

发表评论

登录后才能评论

评论列表(0条)

保存