el-select 组件 懒加载 可远程搜索

用于分页数据的懒加载 vue+elment
新建elSelct.vue 组件

<template><div><el-select v-el-select-loadmore="loadMore" :value="defaultValue" :loading="loading" :multiple="multiple":placeholder="placeholder" :allow-create="allowCreate" filterable remote clearable:remote-method="(query) => {remoteMethod(query, value)}" style="width: 100%;" @change="change"@input="$emit('input',$event)" @visible-change="visibleChange" @clear="clearChange"><el-option v-if="hasAll" :label="defaultLabel" value="" /><el-option v-for="(item,index) in optionsList" :key="item.index+'s'+item.id":label="concatString2(item[label], item[labelTwo])" :value="item[valueString]">{{ concatString(item[label], item[labelTwo]) }}</el-option></el-select></div>
</template><script>export default {name: 'YSelect',directives: {'el-select-loadmore': {bind(el, binding) {// 获取element-ui定义好的scroll盒子const DOM = el.querySelector('.el-select-dropdown .el-select-dropdown__wrap')DOM.addEventListener('scroll', function() {/*** scrollHeight 获取元素内容高度(只读)* scrollTop 获取或者设置元素的偏移值,常用于, 计算滚动条的位置, 当一个元素的容器没有产生垂直方向的滚动条, 那它的scrollTop的值默认为0.* clientHeight 读取元素的可见高度(只读)* 如果元素滚动到底, 下面等式返回true, 没有则返回false:* ele.scrollHeight - ele.scrollTop === ele.clientHeight;*/const condition = this.scrollHeight - this.scrollTop <= this.clientHeightif (condition) {binding.value()}})}}},props: {// 是否允许创建条目allowCreate: {type: Boolean,default: false},// 需要显示的名称label: {type: String,default: ''},// 需要显示的名称labelTwo: {type: String,default: ''},// 传入的数据,必填value: {type: [String, Number, Array],default: null},// 是否拼接label | valueisConcat: {type: Boolean,default: false},isConcatShowText: {type: Boolean,default: false},// 拼接label、value符号concatSymbol: {type: String,default: ' | '},valueString: {type: String,default: ''},// 选项数据,必填options: {type: Array,default: () => {return []}},// 是否有全部选项hasAll: {type: Boolean,default: true},defaultLabel: {type: String,default: '全部'},// 加载loadingloading: {type: Boolean,default: false},// 提示placeholder: {type: String,default: '请选择'},// 是否支持多选multiple: {type: Boolean,default: false},// 每次显示数量size: {type: Number,default: 100}},data() {return {page: 1,pageRemote: 1,defaultLoading: false,timer: null,optionsList: [],oldOptions: [],isRemote: false,defaultValue:null,}},watch: {options: {handler(val) {if (this.isRemote) {if (val) {this.optionsList = valthis.oldOptions = this.oldOptions.filter((item) => {return !val.some(valItem => item.id === valItem.id)})this.oldOptions = [...this.oldOptions, ...val]}} else {if (val) {this.optionsList = this.optionsList.filter((item) => {return !val.some(valItem => item.id === valItem.id)})this.optionsList = [...this.optionsList, ...val]}}},deep: true},value: {handler(val, oldVal) {this.defaultValue = this.valueif (val==='null' || val===null || val==='undefined' || val===undefined || val===''){this.clearChange()}},immediate: false,deep: true}},mounted() {this.defaultValue = this.valuethis.optionsList = this.options},methods: {//选择后 只显示label//张三concatString(a, b) {a = a || ''b = b || ''if (this.isConcat) {// return a + ((a && b) ? ' | ' : '') + breturn a + ((a && b) ? this.concatSymbol : '') + b}return a},//选择下拉展示时 可以展示label和labelTwo//123||张三concatString2(a, b) {a = a || ''b = b || ''if (this.isConcat) {// return a + ((a && b) ? ' | ' : '') + bif (this.isConcatShowText == true) {return a + ((a && b) ? this.concatSymbol : '') + b} else {return a}}return a},change(val) {console.log('change', val)this.$emit('change', val)},visibleChange(status) {console.log('change2', status)if (!status) {if (this.isRemote) {this.isRemote = falsethis.optionsList = [...this.oldOptions]}}this.$emit('visibleChange', status)},loadMore() {console.log(this.isRemote, this.pageRemote, this.page)if (this.isRemote) {if (this.pageRemote === 1) {this.$emit('loadMore', this.pageRemote)this.pageRemote++} else {this.pageRemote++this.$emit('loadMore', this.pageRemote)}} else {this.page++this.$emit('loadMore', this.page)}},remoteMethod(query) {this.pageRemote = 1if (this.timer) {clearTimeout(this.timer)this.timer = null}this.timer = setTimeout(() => {this.isRemote = truethis.oldOptions = [...this.optionsList]this.optionsList = []this.$emit('remoteMethod', query, this.pageRemote)}, 500)},//清除clearChange() {if (typeof this.defaultValue === 'string') {this.defaultValue = ''} else if (this.isMultiple) {this.defaultValue = []}this.$emit('clear')}}}
</script><style lang='scss' scoped></style>

然后再页面引用
hasAll 是否显示全部2个字 is-concat 是否拼接 concat-symbol拼接符号 is-multiple是否多选 label 字段名称1 labelTwo 字段名称2 valueString要获取的value值,是id还是projectCode options显示的数据 @loadMore加载更多 的方法 @remoteMethod远程请求的方法 @change方法
[{name:'我是名称’,projectCode:‘0121’,id:1}]

<template><YSelect  v-model="form.contractNumber" :hasAll='false' :is-concat="true" :is-multiple="false":isConcatShowText="false" :concat-symbol="' || '" label="name" labelTwo="projectCode"  valueString="id" :options="contractList" :placeholder="'请选择合同编号'"  @loadMore="loadMore" @remoteMethod="remoteMethod" @change="selectContract" @clear='contractClear()'/>
</template>import YSelect from '@/views/components/elSelect/index'
export default {
components: {YSelect},
data:{return(){projectPageNum:0}
},
mounted() {
this.projectSearch()
},
methods: {
//清除
contractClear(){},
//下拉框选中完成后visibleChange(status) {},//下拉框改变时selectChange(){},//项目号 懒加载 下拉加载更多loadMore(page) {let that=thisthat.projectPageNum =pagethis.projectSearch('',true)},//项目号 下拉框的远程搜索remoteMethod(query, page) {this.projectPageNum = pagethis.projectSearch(query,false)},/**项目号搜索 列表展示*/projectSearch(val, lazy = false) {let that = thisif (lazy == false) { // 如果不是懒加载,this.projectList = [] // 把select选项数组重置为空that.projectPageNum = 1 // 设置查询第一页,每页20条}//请求后台数据listInfo({search: val,pageSize: 30,pageNum: that.projectPageNum}).then(response => {that.projectList=response.rows});},
}
}

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/162938.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

LeetCode算法心得——使用最小花费爬楼梯(记忆化搜索+dp)

大家好&#xff0c;我是晴天学长&#xff0c;很重要的思想动规思想&#xff0c;需要的小伙伴可以关注支持一下哦&#xff01;后续会继续更新的。&#x1f4aa;&#x1f4aa;&#x1f4aa; 1&#xff09;使用最小花费爬楼梯 给你一个整数数组 cost &#xff0c;其中 cost[i] 是从…

PTA-使用函数求最大公约数

本题要求实现一个计算两个数的最大公约数的简单函数。 函数接口定义&#xff1a; int gcd( int x, int y ); 其中x和y是两个正整数&#xff0c;函数gcd应返回这两个数的最大公约数。 裁判测试程序样例&#xff1a; #include <stdio.h> int gcd( int x, int y ); i…

【数据结构】深入浅出理解链表中二级指针的应用

&#x1f984;个人主页:修修修也 &#x1f38f;所属专栏:数据结构 ⚙️操作环境:Visual Studio 2022 (注:为方便演示本篇使用的x86系统,因此指针的大小为4个字节) 目录 &#x1f4cc;形参的改变不影响实参! 1.调用函数更改整型时传值调用与传址调用的区别 &#x1f38f;传值…

render函数举例

在这段代码中&#xff0c;renderButton是一个对象吗 还有render为什么不能写成render() {} 代码原文链接 <template><div><renderButton /></div> </template><script setup> import { h, ref } from "vue"; const renderButt…

C#,简单修改Visual Studio 2022设置以支持C#最新版本的编译器,尊享编程之趣

1 PLS README & CHAPTER 5 用一个超简单的例子说明各版本 C# 的差异。 使用新版本&#xff08;比如C#.11&#xff09;&#xff0c;当然有一定的好处。我们在写程序的时候一般这样&#xff1a; Visual Studio 2022 默认只能这样写&#xff1a; string imageFile Path.C…

若依框架参数验证

文章目录 一、前端触发参数校验异常1.前端页面2.前端代码 二、后端触发参数校验异常1.前端页面2.后端报错 三、后端自定义参数验证1.添加注解2.触发后端校验 一、前端触发参数校验异常 1.前端页面 输入不符合校验规则的值来触发 2.前端代码 校验规则数组 表单的元素 修…

SQL Server数据库备份与还原

目录 SQL Server DataBase备份 SQL Server DataBase还原 SQL Server DataBase备份 在 SQL Server 中&#xff0c;你可以使用 SQL Server Management Studio (SSMS) 或 Transact-SQL 语句来手动备份数据库。以下是两种方法&#xff1a; 使用 SQL Server Management Studio (SS…

JAVA小游戏“飞翔的小鸟”

第一步是创建项目 项目名自拟 第二步创建个包名 来规范class 再创建一个包 来存储照片 如下&#xff1a; 代码如下&#xff1a; package game; import java.awt.*; import javax.swing.*; import javax.imageio.ImageIO;public class Bird {Image image;int x,y;int width…

Windows下安装Anaconda3并使用JupyterNoteBook

下载安装包 Anaconda官网 进官网&#xff0c;点击下载 自动根据当前系统下载对应的包了&#xff0c;安装包大约1G&#xff0c;喝杯Java耐心等待。 安装 很多人安装C盘&#xff0c;我这里放D盘。 注意&#xff1a;你的文件夹目录一定要不能有空格 然后其他的直接默认install即…

不同路径 递归

int dfs(int i, int j, int m, int n) { if (i > m || j > n) return 0; // 越界了 if (i m && j n) return 1; // 找到一种方法&#xff0c;相当于找到了叶子节点 return dfs(i 1, j, m, n) dfs(i, j 1, m, n); } int u…

在线视频课程教育系统源码/网课网校/知识付费/在线教育系统/在线课程培训系统源码

源码简介&#xff1a; 在线视频课程教育系统源码&#xff0c;作为网课/网校/知识付费/在线教育系统&#xff0c;它有文章付费阅读在线点播自动发货付费阅读VIP会员系统等功能。它是实用的在线课程培训系统源码。 发货100-在线视频课程教育系统&#xff0c;它是一款功能实用的…

优思学院|2024年质量管理的大趋势

2023年我们已经顺利度过了整年的大部分时间&#xff0c;2024年质量管理的趋势和问题在全球范围内都已经引起了关注&#xff0c;或者仍然是企业导航的首要任务。 1. 通货膨胀与质量管理 2023年&#xff0c;全球范围内通货膨胀和严峻的经济状况成为企业最关心的问题之一。尽管物…

Flash可更换声音语音芯片WT588F02系列:优势尽显,应用广泛

在语音技术日益普及的今天&#xff0c;唯创知音推出的Flash可更换声音语音芯片WT588F02系列备受关注。该系列芯片凭借其强大的性能与广泛的应用领域&#xff0c;成为市场上的一颗璀璨明星。本文将分析WT588F02系列的优势&#xff0c;并探讨其应用场景&#xff0c;以展现其在语音…

typedef 的使用

typedef 的定义 typedef 是 C 和 C 中的一个关键字&#xff0c;用于给已有类型定义一个新的名字&#xff0c;与 class、struct、union 和 enum 声明不同&#xff0c;typedef 声明不引入新类型&#xff1b;它们引入现有类型的新名称 typedef 的语法格式 typedef existing_typ…

gitlab 12升级14(解决各种报错问题)

1.这里是从自己公司的源下载的rpm包&#xff0c;需要换成自己的 2.从12的最后一个版本升级到14的最后一个版本 # 停服务 [rootdocker test]# gitlab-ctl stop puma && gitlab-ctl stop sidekiq && gitlab-ctl stop nginx && gitlab-ctl status# 进入…

前端如何判空

这样判空就会报错 loadNode(node, resolve)console.log("node")console.log(node)if (node.data ! null) {this.get(ctx /publicity/publicityType/typeTreeData?id node.data.id).then((res) > {resolve(res)})}}, 需要这样写&#xff0c;用typeof来做类型判…

【webrtc】ModuleRtpRtcpImpl2: RtpRtcp DEPRECATED_Create 废弃了

基于m98 代码。Deprecate the static RtpRtcp::Create() method. 提交记录RtpRtcp::Create factory method 工厂方法废弃了。std::unique_ptr<RtpRtcp> RtpRtcp::DEPRECATED_Create(const Configuration& configuration) {RTC_DCHECK

java 实现发送邮箱,复制即用,包含邮箱设置第三方登录授权码获取方法

application.yml spring:profiles:active: dev # active: test#邮件附件上传文件大小限制servlet:multipart:max-file-size: 50MB #单个文件大小限制max-request-size: 100MB #总文件大小限制&#xff08;允许存储文件的文件夹大小&#xff09;mail:default-encoding: UTF…

【开题报告】基于SpringBoot的机车模型交流平台的设计与实现

1.研究背景 机车模型是一种受到广泛关注的模型制作爱好&#xff0c;它涵盖了机车模型的收藏、展示、制作等多个方面。然而&#xff0c;由于机车模型爱好者的数量较少&#xff0c;且分散在不同的地区和社区&#xff0c;导致他们难以进行互动和资源共享。因此&#xff0c;需要一…

COBOL排序问题

*SORT排序文件文件超长&#xff0c;将主键保存在临时文件里&#xff0c;超长的数据从数组里面去检索获取。 IDENTIFICATION DIVISION. PROGRAM-ID. TEST002. * ENVIRONMENT DIVISION. CONFIGURATION SECTION. …