el-select滚动到底部加载更多(分页加载数据)
Sonder
2022-11-09
1002字
3分钟
浏览 (2.5k)
自定义指令:
directives: {
'loadmore': {
inserted(el, binding) {
const SELECTWRAP_DOM = el.querySelector('.el-select-dropdown .el-select-dropdown__wrap');
SELECTWRAP_DOM.addEventListener('scroll', function() {
const condition = this.scrollHeight - this.scrollTop <= this.clientHeight;
if (condition) {
binding.value();
}
});
}
}
},
引用自定义指令
<el-form-item v-if="ruleForm.organizationType == 1" label="站点:" prop="stationId">
<el-select placeholder="站点" v-model="ruleForm.stationId" :disabled="ruleForm.operatorId.length<=0" style="width:100%" v-loadmore="loadMore">
<el-option v-for="(n,i) in siteList" :key="i" :label="n.stationName" :value="n.id"</el-option>
</el-select>
</el-form-item>
methods:
loadMore() {
// 在这里请求接口加载数据
console.log("滚动到底部了")
},
本文转自 https://blog.csdn.net/ld395353765/article/details/125499026, 如有侵权,请联系删除。