自定义滑动到底部触发指令,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,
        }
      })
    )
  })
},
相关推荐
Awu12273 分钟前
⚡精通Claude第6课-Hooks钩子系统:从前端视角玩转AI自动化工作流
前端·aigc·claude
椰猫子4 分钟前
Spring Framework(Bean)
java·前端·spring
道清茗5 分钟前
【RH294知识点汇总】第 7 章 《 使用角色和 Ansible 内容集合简化 Playbook 》
java·前端·ansible
前端那点事13 分钟前
彻底弄懂async/await!解决回调地狱,Vue异步开发必备(超全实战)
前端·vue.js
A_nanda36 分钟前
VS2022安装QT6.5.3后,如何更新项目配置
前端·javascript·vue.js
ZC跨境爬虫38 分钟前
UI前端美化技能提升日志day8:(Watch专区字体优化+尺寸校准+视觉重构+结构分层)
前端·ui·重构·html
悟空和大王1 小时前
内网环境: vue3中使用 iconify 的在线图标
前端
福大大架构师每日一题1 小时前
openclaw v2026.4.21 更新:图像生成、权限安全、插件修复、Slack 线程、浏览器与 npm 安装全面优化
前端·安全·npm
FanetheDivine1 小时前
自定义useChat管理AI会话
前端·react.js·aigc
小赵同学WoW1 小时前
call(), appy(),bind() 之间的区别与使用方法,自己实现这三个函数
前端