自定义滑动到底部触发指令,elementUI实现分页下拉框

在 main.js 中添加

js 复制代码
// 自定义滑动到底部指令
Vue.directive('selectLoadMore', {
  bind(el, binding) {
    // 获取element-ui定义好的scroll盒子
    const SELECTWRAP_DOM = el.querySelector('.el-select-dropdown .el-select-dropdown__wrap')
    SELECTWRAP_DOM.addEventListener('scroll', function () {
      if (this.scrollHeight - this.scrollTop < this.clientHeight + 1) {
        binding.value()
      }
    })
  },
})

使用

vue 复制代码
<el-select
  class="width-max"
  v-model="formValues.hpNumberArr"
  clearable
  filterable
  multiple
  reserve-keyword
  remote
  v-selectLoadMore="selectLoadMore"
  :remote-method="remoteMethod"
  placeholder="请选择表型匹配"
>
  <el-option
    v-for="user in phenotypeList"
    :key="user.id"
    :label="user.label"
    :value="user.value"
  >
  </el-option>
</el-select>
js 复制代码
// 下拉加载更多
selectLoadMore() {
  this.phenotypeSearch.pageNum = this.phenotypeSearch.pageNum + 1
  if (this.phenotypeList.length >= this.phenotypeSearch.totalPage) return
  this.readAllUsers() // 请求接口
},
// 远程搜索
remoteMethod(query, callback) {
  this.loading = true
  this.phenotypeSearch.cn = query
  this.phenotypeSearch.pageNum = 1
  this.phenotypeList = []
  callback && callback()
  setTimeout(() => {
    this.loading = false
    this.readAllUsers() // 请求接口
  }, 200)
},
// 获取数据
readAllUsers() {
  let params = {
    pageNum: this.phenotypeSearch.pageNum,
    pageSize: this.phenotypeSearch.pageSize,
    cn: this.phenotypeSearch.cn,
  }
  findListByConditionFun(params).then((res) => {
    this.phenotypeSearch.totalPage = res.data.totalRecords
    this.phenotypeList = this.phenotypeList.concat(
      res.data.data.map((i) => {
        return {
          id: i.id,
          value: i.hpNumber,
          label: i.cn,
        }
      })
    )
  })
},
相关推荐
前端九哥2 分钟前
🚫循环里写return,浏览器当场沉默!
前端·javascript
亲爱的马哥9 分钟前
填鸭表单!开箱即用的开源问卷调查系统!
java·前端·低代码·产品经理
米诺zuo18 分钟前
nextjs文件路由、路由组
前端·next.js
加个鸡腿儿19 分钟前
锚点跳转-附带CSS样式 & 阻止页面刷新技术方案
前端·javascript·css
dragon72538 分钟前
FutureProvider会刷新两次的问题研究
前端·flutter
天蓝色的鱼鱼1 小时前
Next.js路由全解析:Pages Router 与 App Router,你选对了吗?
前端·next.js
xun_xing1 小时前
基于Nextjs15的学习手记
前端·javascript·react.js
有意义1 小时前
Vibe Coding:人机共生时代的开发革命 —— 从概念到 Chrome 扩展实战
前端·ai编程·vibecoding
梅梅绵绵冰1 小时前
SpringMVC快速入门
前端
kirkWang1 小时前
HarmonyOS 6.0 服务卡片实战:把「轻食刻」装进桌面,让轻断食一眼可控
前端