news 2026/7/7 10:21:29

elementUI的select下拉框如何下拉加载数据?

作者头像

张小明

前端开发工程师

1.2k 24
文章封面图
elementUI的select下拉框如何下拉加载数据?

前言

相信大家都遇到过一个问题,select下拉选项数据特别多,要设置为分页,那么前端如何弄成下拉加载数据呢?来看看我是怎么弄的吧。

先来看看效果

template代码

<el-select v-model="formDataModel[item.key]":placeholder="'请选择' + item.label"filterable remote clearable:remote-method="remoteMethod"@clear="handleClear"@blur="handleBlur"><divclass="options"v-infinite-scroll="load":infinite-scroll-disabled="disabled"v-loading="isLoading"><el-option v-for="(item, index) in options":key="index":label="item.name":value="`${item.name}-${item.id}`"></el-option><pclass="load-text"v-if="loading">加载中...</p><pclass="load-text"v-if="noMore">没有更多了</p></div></el-select>

js代码

// 弹框组件是否显示@Prop({type:Boolean,default:false})isShow!:boolean;@Watch('isShow',{immediate:true})handleShowChange(val:boolean){if(val){this.keyword='';this.pageIndex=1;this.getOptions();}}// 清空选项publichandleClear(){this.remoteMethod('');}// 处理失去焦点publichandleBlur(){setTimeout(()=>{if(!this.formDataRef.formDataModel.VBIFieldName){this.remoteMethod('');}},500);}//#region 下拉加载开始publicpageIndex=1;publicoptions:any[]=[];publicloading=false;// 总数publictotal=0;getnoMore(){returnthis.options.length>=this.total;}getdisabled(){returnthis.loading||this.noMore;}publicasyncload(){this.pageIndex+=1;this.getVBIFieldNameOptions();}//#endregion 下拉加载结束publickeyword='';publicisLoading=false;//获取选项publicasyncgetOptions(){if(this.pageIndex===1){// 搜索loadingthis.isLoading=true;}else{// 下拉加载loadingthis.loading=true;}try{letfetchApi:any;letparamsData={pageIndex:this.pageIndex,pageSize:10,name:this.keyword};const{data:{data:{records,total}}}=awaitfetchApi(paramsData);letlist=records??[];if(this.pageIndex===1){this.options=list;}else{this.options=[...this.options,...list];}this.total=total;}finally{if(this.pageIndex===1){// 搜索loadingthis.isLoading=false;}else{// 下拉加载loadingthis.loading=false;}}}// 根据输入框的值远程查询publicasyncremoteMethod(query:string){this.pageIndex=1;this.keyword=query;this.getVBIFieldNameOptions();}

css代码

.options{.load-text{margin:0;text-align:center;color:#999;font-size:12px;}}

结语

大家可以参考一下实现逻辑,代码可能不能直接使用。

关注我,不迷路。
不定时分享前端相关问题以及解决方案。
希望能帮助每个在开发类似功能的小伙伴。

版权声明: 本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若内容造成侵权/违法违规/事实不符,请联系邮箱:809451989@qq.com进行投诉反馈,一经查实,立即删除!
网站建设 2026/7/7 16:50:26

【限时揭秘】Open-AutoGLM内部架构曝光:掌握这7个模块你也能造AI引擎

第一章&#xff1a;Open-AutoGLM技术演进与核心定位Open-AutoGLM 是新一代开源自动推理语言模型框架&#xff0c;致力于融合生成式语言模型&#xff08;GLM&#xff09;与自动化任务执行能力&#xff0c;推动AI代理在复杂场景下的自主决策与执行效率。其设计初衷是解决传统LLM在…

作者头像 李华
网站建设 2026/7/7 12:10:50

Blender 3MF插件实战指南:从零开始玩转3D打印文件

还在为3D打印文件的转换烦恼吗&#xff1f;&#x1f3af; 今天我要为你介绍一款改变游戏规则的Blender插件——Blender 3MF插件&#xff01;这个强大的工具让你在Blender中轻松处理3MF格式文件&#xff0c;无论是导入还是导出都变得简单快捷。作为专业的3D制造格式&#xff0c;…

作者头像 李华
网站建设 2026/7/7 19:25:33

Blender 3MF插件终极指南:3D打印工作流一键优化方案

Blender 3MF插件终极指南&#xff1a;3D打印工作流一键优化方案 【免费下载链接】Blender3mfFormat Blender add-on to import/export 3MF files 项目地址: https://gitcode.com/gh_mirrors/bl/Blender3mfFormat Blender 3MF插件是专为3D打印设计流程量身打造的专业工具…

作者头像 李华