自定义滑动到底部触发指令,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,
        }
      })
    )
  })
},
相关推荐
顾安r2 小时前
11.8 脚本网页 星际逃生
c语言·前端·javascript·flask
Hello.Reader2 小时前
Data Sink定义、参数与可落地示例
java·前端·网络
im_AMBER2 小时前
React 17
前端·javascript·笔记·学习·react.js·前端框架
谷歌开发者3 小时前
Web 开发指向标 | Chrome 开发者工具学习资源 (六)
前端·chrome·学习
一晌小贪欢3 小时前
【Html模板】电商运营可视化大屏模板 Excel存储 + 一键导出(已上线-可预览)
前端·数据分析·html·excel·数据看板·电商大屏·大屏看板
发现你走远了3 小时前
连接模拟器网页进行h5的调试(使用Chrome远程调试(推荐)) 保姆级图文
前端·chrome
街尾杂货店&4 小时前
css - 实现三角形 div 容器,用css画一个三角形(提供示例源码)简单粗暴几行代码搞定!
前端·css
顺凡5 小时前
删一个却少俩:Antd Tag 多节点同时消失的原因
前端·javascript·面试
小白路过5 小时前
CSS transform矩阵变换全面解析
前端·css·矩阵
爬山算法5 小时前
Redis(110)Redis的发布订阅机制如何使用?
前端·redis·bootstrap