当前位置:网站首页>How to implement lazy loading in El select (with search function)
How to implement lazy loading in El select (with search function)
2022-07-04 05:42:00 【_ Virgo programmer's daily life】
<!--
<template>
<el-select
:value="value"
v-loadmore="loadMore"
@focus="focus"
@clear="clear"
filterable
remote
:filter-method="handleSearch"
:loading="loading"
clearable
v-bind="$attrs"
v-on="$listeners"
>
<el-option
v-for="option in data"
:label="option[dictLabel]"
:value="option[dictValue]"
:key="option.value"
></el-option>
<!-- Loaded here value You can set whatever you like , As long as it does not duplicate other data -->
<el-option
v-if="hasMore"
disabled
label=" Loading ..."
value="-1"
></el-option>
</el-select>
</template>
<script>
export default {
props: {
value: {
default: ""
},
// The list of data
data: {
type: Array,
default: () => []
},
dictLabel: {
type: String,
default: "label"
},
dictValue: {
type: String,
default: "value"
},
// Call the interface of page number
request: {
type: Function,
default: () => {
}
},
// Incoming page number
page: {
type: [Number, String],
default: 1
},
// Is there any more data
hasMore: {
type: Boolean,
default: true
}
},
directives: {
// Here we implement a custom instruction inside the component
loadmore: {
// Definition of instruction
bind(el, binding) {
const SELECTWRAP = el.querySelector(
".el-select-dropdown .el-select-dropdown__wrap"
);
if (!SELECTWRAP) {
throw new Error(' Can't get "el-select-dropdown__wrap" node ');
}
SELECTWRAP.addEventListener("scroll", () => {
// scrollTop Here, there may be a decimal point in browser scaling , This leads to rolling to the bottom
// scrollHeight Subtract... When scrolling to the bottom scrollTop , Still greater than clientHeight Unable to request more data
// There will be scrollTop Rounding up Make sure to roll to the bottom , Trigger call
const CONDITION =
SELECTWRAP.scrollHeight -
Math.ceil(SELECTWRAP.scrollTop) <=
SELECTWRAP.clientHeight;
// el.scrollTop !== 0 When typing , If there are few search results , So that I don't see the scroll bar , So the CONDITION The result is true, Will execute bind.value(), It should not be executed at this time , Otherwise, the search results do not match
if (CONDITION && SELECTWRAP.scrollTop !== 0) {
binding.value();
}
});
}
}
},
data() {
return {
keyword: "", // Store keywords with
loading: false
};
},
methods: {
// Request data for the next page
loadMore() {
// Without more data , Do not ask for
if (!this.hasMore) {
return;
}
// If intercept The attribute is true Do not request data ,
if (this.loadMore.intercept) {
return;
}
this.loadMore.intercept = true;
this.request({
page: this.page + 1,
more: true,
keyword: this.keyword
}).then(() => {
this.loadMore.intercept = false;
});
},
// When there is no data in the selected drop-down box , Automatically request the data of the first page
focus() {
if (!this.data.length) {
this.request({
page: 1 });
}
},
handleSearch(keyword) {
this.keyword = keyword;
this.loading = true;
console.log(keyword);
this.request({
page: 1, keyword: keyword }).then(() => {
this.loading = false;
});
},
// Delete when selected , If a keyword is requested , Then clear the keyword and request the data on the first page
clear() {
if (this.keyword) {
this.keyword = "";
this.request({
page: 1 });
}
}
}
};
</script>
Reference article :
el-select Pull down load
边栏推荐
- 19.Frambuffer应用编程
- Notepad++ -- display related configurations
- input显示当前选择的图片
- Risc-v-qemu-virt in FreeRTOS_ Lock mechanism analysis of GCC
- VB.net GIF(制作、拆解——优化代码,类库——5)
- Recommended system 1 --- framework
- Flink1.13 basic SQL syntax (II) join operation
- Just do it with your hands 7 - * project construction details 2 - hook configuration
- Letter meaning and parameter abbreviation of optical module Daquan
- Flink1.13 SQL basic syntax (I) DDL, DML
猜你喜欢
随机推荐
724. 寻找数组的中心下标
Excel comparator
Google Chrome browser will support the function of selecting text translation
Etcd database source code analysis - initialization overview
检漏继电器JY82-2P
Analysis of classical pointer and array written test questions in C language
Luogu deep foundation part 1 Introduction to language Chapter 5 array and data batch storage
VB. Net calls ffmpeg to simply process video (class Library-6)
js获取对象中嵌套的属性值
VB. Net GIF (making and disassembling - optimizing code, class library - 5)
(4) Canal multi instance use
Penetration tool - sqlmap
Flink1.13 SQL basic syntax (I) DDL, DML
Risc-v-qemu-virt in FreeRTOS_ Lock mechanism analysis of GCC
The data mark is a piece of fat meat, and it is not only China Manfu technology that focuses on this meat
BeanFactoryPostProcessor 与 BeanPostProcessor 相关子类概述
509. 斐波那契数、爬楼梯所有路径、爬楼梯最小花费
BUU-Reverse-easyre
Accidentally deleted the data file of Clickhouse, can it be restored?
[microservice] Nacos cluster building and loading file configuration








![[paper summary] zero shot semantic segmentation](/img/78/ee64118d86a7e43ec4d1cb97191fbe.jpg)
