当前位置:网站首页>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
边栏推荐
- Easy change
- left_and_right_net可解释性设计
- JS string splicing
- 拓扑排序和关键路径的图形化显示
- Install pytoch geometric
- Halcon image calibration enables subsequent image processing to become the same as the template image
- Evolution of system architecture: differences and connections between SOA and microservice architecture
- FreeRTOS 中 RISC-V-Qemu-virt_GCC 的 锁机制 分析
- [wechat applet] template and configuration (wxml, wxss, global and page configuration, network data request)
- 19.Frambuffer应用编程
猜你喜欢
VB.net GIF(制作、拆解——优化代码,类库——5)
Flask
19.Frambuffer应用编程
509. Fibonacci number, all paths of climbing stairs, minimum cost of climbing stairs
Letter meaning and parameter abbreviation of optical module Daquan
Solar insect killing system based on single chip microcomputer
c语言经典指针和数组笔试题解析
SQL injection - injection based on MSSQL (SQL Server)
LM small programmable controller software (based on CoDeSys) note XXI: error 3703
How to configure static IP for Kali virtual machine
随机推荐
Use of hutool Pinyin tool
Graduation design of small programs -- small programs of food and recipes
Tutle clock improved version
What is MQ?
The data mark is a piece of fat meat, and it is not only China Manfu technology that focuses on this meat
SQL injection - injection based on MSSQL (SQL Server)
Flask
"In simple language programming competition (basic)" part 1 Introduction to language Chapter 3 branch structure programming
JS string splicing
Write a complete answer applet (including single choice questions, judgment questions and multiple topics) (III) single choice questions, judgment questions, and the first question display
Excel comparator
left_ and_ right_ Net normal version
Redis realizes ranking function
Penetration tool - sqlmap
Viewing and using binary log of MySQL
Halcon image calibration enables subsequent image processing to become the same as the template image
724. Find the central subscript of the array
2022g2 power station boiler stoker special operation certificate examination question bank and answers
Online shrimp music will be closed in January next year. Netizens call No
十二. golang其他