AntDesingVue select下拉框中数据量过多,响应慢。使用popupScroll,下拉加载更多
在做公司的项目时,需要将行政区与区块联系下拉,导致加载的数据过多,页面响应慢,因此可以考虑使用分页的方式,用户在下拉到底部时加载更多的数据,一直到数据加载完。
ant design for vue 的select提供了popupScroll方法
具体的实现如下
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | < a-select style="width: 100%" show-search placeholder="请选择" search-placeholder="请选择" :dropdown-style="{ maxHeight: '240px', overflow: 'auto' }" :value="value" @change="onChange" @search="searchChange" @popupScroll="popupScroll" :filter-option="false" not-found-content="暂无数据" > < a-select-option v-for="item in treeData" :key="item.code" :data="item" :value="item.code" :title=" item.pathName"> {{ item.pathName}} </ a-select-option > </ a-select > |
pageSize: 10, // 分页
pageNumber: 1,
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 | getListDataCode(code = '' ) { // 获取树节点 let self = this ; this .$post(self.$api.getCompanyList, { code: code, systemCode: 'SYSTEM' , fullName:self.searchName, pageNumber: this .pageNumber, pageSize: this .pageSize, }).then((res) => { if (res.code - 0 === 200) { const resData = (res.data && res.data) || [] this .pages= res.data.pages; if ( this .treeData.length <= resData.total){ this .treeData.push(...resData.records); } } }) }, // 文本框的值变化是 searchChange(searchValue){ this .searchName = searchValue if ( this .searchName){ this .treeData = [] this .pageNumber = 1; this .getListDataCode( this .parentCode) } }, // 选中时调用 onChange(value,e){ this .searchName = value; let data = e && e.data && e.data.attrs && e.data.attrs.data this .$emit( 'select' , {...data, value, name: data.pathName}) }, popupScroll(e){ const {target} = e; const scrllHeight = target.scrollHeight - target.scrollTop; const clientHeight = target.clientHeight; // 下拉框不下拉的时候 if (scrllHeight ===0 && clientHeight ===0){ this .pageNumber = 1; } else if (scrllHeight - clientHeight == 0){ // 下拉到底部时 if ( this .pageNumber < this .pages){ // 如果滑到底部,则加载下一页 this .pageNumber++ this .getListDataCode( this .parentCode) } } } |
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 25岁的心里话
· 闲置电脑爆改个人服务器(超详细) #公网映射 #Vmware虚拟网络编辑器
· 基于 Docker 搭建 FRP 内网穿透开源项目(很简单哒)
· 零经验选手,Compose 一天开发一款小游戏!
· 一起来玩mcp_server_sqlite,让AI帮你做增删改查!!