自定义滑动到底部触发指令,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 分钟前
小程序错误日志链路处理规范
前端·javascript·微信小程序
小钰能吃三碗饭5 分钟前
第十篇:【React SSR 与 SSG】服务端渲染与静态生成实战指南
前端·react.js·next.js
江城开朗的豌豆6 分钟前
CSS篇:告别单调背景:CSS渐变的20种惊艳用法
前端·css·面试
江城开朗的豌豆6 分钟前
CSS篇:Flex布局核心属性详解:flex-grow/shrink/basis到底怎么用?
前端·css·面试
乡关何处7 分钟前
vue Element-ui对图片上传和选用时的比例控制
前端
Danny_FD7 分钟前
前端盒模型详解
前端·css
洛小豆7 分钟前
深入理解 JavaScript 的解构赋值
前端·javascript·typescript
樊小肆8 分钟前
Vue3 在线 PDF 编辑 1.0 保存、下载
前端·vue.js
WEI_Gaot8 分钟前
2 认识js的面向对象 和 Object 的属性描述符
前端·javascript
curdcv_po8 分钟前
🎉🚀React封装 微信扫码 登录组件
前端