第一种方法:添加分页,页面样式如下,JS逻辑与平常分页没区别
<el-select :disabled="noChange[index]==true || applyDataItem.processKey == 'componentFastAdd'" style="width:68%" v-model="chooseUser[index]" clearable filterable placeholder="请选择人员"> <div class="option"> <el-option v-for="user in allUsers" :key="user.id" :label="user.userName" :value="user.id"> </el-option> </div> <div class="pagin"> <el-pagination small @size-change="sizeChange" :current-change="currentChange" :page-size="pageSize" layout="prev, pager,next,total" :total="total" > </el-pagination> </div> </el-select>
css
.option{ min-height: 100px; height: auto; max-height: 200px; overflow-y: auto; } .pagin{ background:#fff; } ::-webkit-scrollbar{ width: 2px; }
第二种方法:下拉加载更多
1.写一个指令
/** * select 下拉框 底部触发指令 */ 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() } }) } })
2.页面使用指令,添加远程搜索属性和方法
<el-select style="width:68%" v-model="chooseUser[index]" clearable filterable v-selectLoadMore="selectLoadMore" :loading="loading" remote :remote-method="remoteMethod" placeholder="请选择人员"> <el-option v-for="user in allUsers" :key="user.id" :label="user.userName" :value="user.id"> </el-option> </el-select>
3.JS写逻辑
// 下拉加载更多 selectLoadMore() { this.search.pageNum = this.search.pageNum + 1; if (this.search.pageNum > this.totalPage) return; this.readAllUsers(); // 请求接口 }, // 远程搜索 remoteMethod(query) { this.loading = true; this.search.query = query; this.search.pageNum = 1; this.allUsers = []; setTimeout(() => { this.loading = false; this.readAllUsers(); // 请求接口 }, 200) }, // 获取数据 readAllUsers() { let params = { num:this.search.pageNum, size:this.search.pageSize, userName:this.search.query, } readUserPageList(params).then((res) => { this.totalPage = res.pages; this.total = res.total; this.allUsers = this.allUsers.concat(res.data); }); },
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· 开发者必知的日志记录最佳实践
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· 无需6万激活码!GitHub神秘组织3小时极速复刻Manus,手把手教你使用OpenManus搭建本
· Manus爆火,是硬核还是营销?
· 终于写完轮子一部分:tcp代理 了,记录一下
· 别再用vector<bool>了!Google高级工程师:这可能是STL最大的设计失误
· 单元测试从入门到精通