el-select下拉选项数据如果太多会很卡(我这里上万条) 解决的方法有很多 我这里用的是类似于移动端下滑加载更多
先在main.js里面定义自定义指令 也可以用文件引入方式,看个人。
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()
}
})
}
})
然后使用vue文件使用
this.getEnterpriseInformationPage方法是自己的初始化查询
getEnterpriseInformationPage() {
getEnterpriseInformationPage(this.queryParamsOp2).then(res => {
this.queryParamsOp2.total = res.data.total
this.options2 = this.options2.concat(res.data.list);
})
},
<el-select v-model="form.enterpriseId" placeholder="请选择企业" filterable
v-selectLoadMore="selectLoadMore2" :remote-method="parentOperatorNameChange2">
<el-option v-for="item in options2" :key="item.id" :label="item.name" :value="item.id + ''" />
</el-select>
//下滑加载
selectLoadMore2() {
this.queryParamsOp2.pageNo = this.queryParamsOp2.pageNo + 1; //查询搜索参数
if (this.queryParamsOp2.pageNo > this.queryParamsOp2.total) return;
this.getEnterpriseInformationPage(); //查询方法
},
//远程搜索
parentOperatorNameChange2(query) {
if (query !== "") {
this.queryParamsOp2.name = query;
this.queryParamsOp2.pageNo = 1;
this.getEnterpriseInformationPage();
} else {
this.options2 = [];
}
},