自定义滑动到底部触发指令,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,
        }
      })
    )
  })
},
相关推荐
VX:Fegn0895几秒前
计算机毕业设计|基于springboot + vue教务管理系统(源码+数据库+文档)
vue.js·spring boot·课程设计
梅梅绵绵冰5 分钟前
springboot初步1
java·前端·spring boot
星辰_mya9 分钟前
nginx之待续-没写完
前端
Irene199115 分钟前
Vue3中 <slot >不支持 ref 属性的替代方案
vue.js·ref
GISer_Jing25 分钟前
大语言模型Agent入门指南
前端·数据库·人工智能
多仔ヾ32 分钟前
Vue.js 前端开发实战之 10-网络请求和 UI 组件库
vue.js
运筹vivo@36 分钟前
BUUCTF: [极客大挑战 2019]Upload
前端·web安全·php·ctf
qq_124987075339 分钟前
基于Spring Boot的长春美食推荐管理系统的设计与实现(源码+论文+部署+安装)
java·前端·spring boot·后端·毕业设计·美食·计算机毕业设计
运筹vivo@41 分钟前
攻防世界: easyupload
前端·web安全·php·ctf
UI设计兰亭妙微1 小时前
兰亭妙微:以HTML前端、UI/交互/图标设计赋能数字孪生与大屏设计新标杆
前端·ui·用户体验设计