当前位置:网站首页>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
边栏推荐
- transformer坑了多少算力
- [paper summary] zero shot semantic segmentation
- Letter meaning and parameter abbreviation of optical module Daquan
- LabVIEW错误对话框的出现
- Basic concept of bus
- 总线的基本概念
- HMS v1.0 appointment.php editid参数 SQL注入漏洞(CVE-2022-25491)
- 力扣(LeetCode)184. 部门工资最高的员工(2022.07.03)
- C language simple student management system (including source code)
- 19.Frambuffer应用编程
猜你喜欢
Introduction To AMBA 简单理解
Simulink and Arduino serial port communication
基于单片机的太阳能杀虫系统
1480. Dynamic sum of one-dimensional array
LabVIEW错误对话框的出现
HMS v1.0 appointment.php editid参数 SQL注入漏洞(CVE-2022-25491)
Halcon image calibration enables subsequent image processing to become the same as the template image
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
ANSYS command
Enterprise level log analysis system elk (if things backfire, there must be other arrangements)
随机推荐
C # character similarity comparison general class
Design and implementation of tcp/ip series overview
Accidentally deleted the data file of Clickhouse, can it be restored?
[wechat applet] template and configuration (wxml, wxss, global and page configuration, network data request)
fastjson
Flink1.13 SQL basic syntax (I) DDL, DML
The difference between PX EM rem
SQL injection - injection based on MSSQL (SQL Server)
Halcon image calibration enables subsequent image processing to become the same as the template image
Basic concept of bus
Build an Internet of things infrared temperature measuring punch in machine with esp32 / rush to work after the Spring Festival? Baa, no matter how hard you work, you must take your temperature first
el-select如何实现懒加载(带搜索功能)
BUU-Pwn-test_ your_ nc
谷歌 Chrome 浏览器将支持选取文字翻译功能
补某视频网站的js,进行视频解密
配置交叉编译工具链和环境变量
Notepad++ -- display related configurations
BUU-Crypto-Cipher
[interested reading] advantageous filtering modeling on long term user behavior sequences for click through rate pre
win10清除快速访问-不留下痕迹