当前位置: 首页 > news >正文

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

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

  • 1.实现效果
  • 2.实现原理

1.实现效果

老规矩,直接上最后的实现效果
在这里插入图片描述

2.实现原理

直接上代码

   <el-form-item class="diagmosisItem" label="诊断" v-scroll="handleScroll"><el-selectsize="small"remotefilterableclearable:loading="getAllDiagnosisLoading"v-model="queryObj.diagnosisDesc":remote-method="handleRemoteDisease"@clear="handleClearDisease"><el-optionv-for="item in allDiagnosisList":key="item.valueId":label="item.valueNo +' '+ item.valueDesc":value="item.valueDesc"></el-option></el-select></el-form-item>
//js
//mothodshandleScroll() {if(!this.scrollStop) {this.diagnosisQuery.pageNo++this.getAllDiagnosis(this.diagnosisQueryText, 'join')}},// 远程搜索诊断async handleRemoteDisease(keyword = '') {this.diagnosisQueryText = keywordthis.getAllDiagnosis(keyword)},// 清除选中诊断handleClearDisease() {this.getAllDiagnosis('', 'clear')},//诊断列表async getAllDiagnosis(val = '', type = 'search') {try {this.getAllDiagnosisLoading = truethis.scrollStop = falselet res = nullif(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.allDiagnosisListthis.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.clientHeightif(CONDITION) {binding.value()}})}}},

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

http://www.lryc.cn/news/193984.html

相关文章:

  • 【Java 进阶篇】JavaScript电灯开关案例:从原理到实现
  • 并发、并行、同步、异步、阻塞、非阻塞
  • C语言:冒泡排序
  • Android 内容提供者和内容观察者:数据共享和实时更新的完美组合
  • 六、K8S之StatefulSet
  • 基于微服务+Java+Spring Cloud开发的建筑工地智慧平台源码 云平台多端项目源码
  • 微信小程序异常:navigateTo:fail can not navigateTo a tabbar page
  • 智慧公厕高精尖技术揭秘,让卫生管理更智能、更舒适
  • Spring Cloud的革新:服务网格和云原生整合
  • EfficientDet: Scalable and Efficient Object Detection
  • 【数据结构】二叉树链式存储及遍历
  • 数字孪生技术:新零售的未来之路
  • NIO教程
  • 【MySQL】表的内连和外连
  • 文心一言:文心大模型 4.0 即将发布
  • HTML笔记
  • design compiler中的drc规则详解
  • CEC2013(MATLAB):螳螂搜索算法(Mantis Search Algorithm,MSA)求解CEC2013
  • 【错误:No package snapd available.】在 CentOS 上启用 snap 并安装 snapd
  • Shell命令笔记2
  • 怎么团队合作,协作开发
  • python 练习--更新
  • 【Java 进阶篇】JavaScript 事件详解
  • 动态内存管理+柔性数组+经典笔试题
  • SQL和Python,哪个更容易自学?哪个更适合数据工作的编程新手?
  • 修改CDB的max_string_size,从STANDARD到EXTENDED
  • Python 字典
  • 【nginx】nginx部署升级htpp+websocket访问
  • C# 生成JWT的Token
  • C# AnimeGAN 漫画风格迁移 动漫风格迁移 图像卡通化 图像动漫化