vue elementui的select组件实现滑到底部分页请求后端接口

vue elementui的select组件实现滑到底部分页请求后端接口

1.实现效果

老规矩,直接上最后的实现效果

2.实现原理

直接上代码

javascript 复制代码
   <el-form-item class="diagmosisItem" label="诊断" v-scroll="handleScroll">
            <el-select
            size="small"
              remote
              filterable
              clearable
              :loading="getAllDiagnosisLoading"
              v-model="queryObj.diagnosisDesc"
              :remote-method="handleRemoteDisease"
              @clear="handleClearDisease"
              >
              <el-option
                v-for="item in allDiagnosisList"
                :key="item.valueId"
                :label="item.valueNo +' '+ item.valueDesc"
                :value="item.valueDesc">
              </el-option>

            </el-select>
          </el-form-item>
//js
//mothods
    handleScroll() {
      if(!this.scrollStop) {
        this.diagnosisQuery.pageNo++
        this.getAllDiagnosis(this.diagnosisQueryText, 'join')
      }
    },
    // 远程搜索诊断
    async handleRemoteDisease(keyword = '') {
      this.diagnosisQueryText = keyword
      this.getAllDiagnosis(keyword)
    },
    // 清除选中诊断
    handleClearDisease() {
      this.getAllDiagnosis('', 'clear')
    },
     //诊断列表
    async getAllDiagnosis(val = '', type = 'search') {
      try {
        this.getAllDiagnosisLoading = true
        this.scrollStop = false
        let res = null
        if(this.isHaveDiagnoseFlag) {
          if(type =='search') {
            this.diagnosisQuery ={
              pageNo:0,
              pageSize:100
            }
            res = await this.reqGetAllDiagnosis({
              keyword:val,
              pageNo:0,
              pageSize:100
            })
          }
          else if(type == 'join') {
            res = await this.reqGetAllDiagnosis({
              keyword:val,
              ...this.diagnosisQuery
            })
          }
          else{
            this.allDiagnosisList = this.allDiagnosisList
            this.getAllDiagnosisLoading = false
          }

        }
        if (res && res.success) {
          if(type =='search') {
            this.allDiagnosisList = res.data
          }
          else{
            if(res.data.length == 0) {
              this.scrollStop = true
            }
            this.allDiagnosisList = [...res.data, ...this.allDiagnosisList]
          }
          this.getAllDiagnosisLoading = false
        }
      } catch (error) {
        this.getAllDiagnosisLoading = false
      }
    },
//主要看这里
  directives:{
    scroll:{
      bind(el, binding) {
        const SELECTNRAP_DON = el.querySelector('.el-select-dropdown .el-select-dropdown__wrap')
        SELECTNRAP_DON.addEventListener( 'scroll', function() {
          console.log(this.scrollHeight - this.scrollTop, this.clientHeight)
          const CONDITION = this.scrollHeight - this.scrollTop <= this.clientHeight
          if(CONDITION) {
            binding.value()
          }
        })
      }
    }
  },

scrollStop主要是用来诊断select移到底部不再请求数据,默认为false。思路反正就是到底了触发函数处理,pageNo++请求后端接口

相关推荐
A_aspectJ1 小时前
【Bootstrap V4系列】学习入门教程之 组件-输入组(Input group)
前端·css·学习·bootstrap·html
兆。1 小时前
电子商城后台管理平台-Flask Vue项目开发
前端·vue.js·后端·python·flask
互联网搬砖老肖2 小时前
Web 架构之负载均衡全解析
前端·架构·负载均衡
sunbyte2 小时前
Tailwind CSS v4 主题化实践入门(自定义 Theme + 主题模式切换)✨
前端·javascript·css·tailwindcss
风之舞_yjf3 小时前
Vue基础(8)_监视属性、深度监视、监视的简写形式
javascript·vue.js·ecmascript
湛海不过深蓝3 小时前
【css】css统一设置变量
前端·css
程序员的世界你不懂4 小时前
tomcat6性能优化
前端·性能优化·firefox
爱吃巧克力的程序媛4 小时前
QML ProgressBar控件详解
前端
进取星辰4 小时前
21、魔法传送阵——React 19 文件上传优化
前端·react.js·前端框架
wqqqianqian4 小时前
国产linux系统(银河麒麟,统信uos)使用 PageOffice 在线打开Word文件,并用前端对话框实现填空填表
linux·前端·word·pageoffice