当前位置: 首页 > news >正文

住房建设部官方网站办事大厅网上营销网站

住房建设部官方网站办事大厅,网上营销网站,美橙互联网站建设案例,精品网站建设费用磐石网络虚拟列表 列表优化 virtualList 组件封装 virtualList 组件封装 本虚拟列表 要求一次性加载完所有数据 不适合分页 新建一个select.vue 组件页面 <template><div> <el-select transfer"true" :popper-append-to-body"true"popper-class…

虚拟列表 列表优化

  • virtualList 组件封装

virtualList 组件封装

本虚拟列表 要求一次性加载完所有数据 不适合分页
新建一个select.vue 组件页面

<template><div>	<el-select transfer="true"   :popper-append-to-body="true"popper-class="virtualselect"class="virtual-select-custom-style":value="defaultValue"filterable:filter-method="filterMethod"default-first-optionclearable:placeholder="placeholderParams":multiple="isMultiple":allow-create="allowCreate"@visible-change="visibleChange"v-on="$listeners"@clear="clearChange"><virtual-listref="virtualList"class="virtualselect-list":data-key="value":data-sources="selectArr":data-component="itemComponent":keeps="keepsParams":extra-props="{label: label,value: value,labelTwo:labelTwo,isRight: isRight,isConcat: isConcat,isConcatShowText:isConcatShowText,concatSymbol: concatSymbol}"></virtual-list></el-select></div>
</template>
<script>import {validatenull} from '@/utils/validate.js'import virtualList from 'vue-virtual-scroll-list'import ElOptionNode from './el-option-node'export default {components: {'virtual-list': virtualList},model: {prop: 'bindValue',event: 'change'},props: {// 数组list: {type: Array,default() {return []}},// 显示名称1label: {type: String,default: ''},// 显示名称2 labelTwo: {type: String,default: ''},// 标识value: {type: String,default: ''},// 是否拼接label | valueisConcat: {type: Boolean,default: false},isConcatShowText:{type: Boolean,default: false},// 拼接label、value符号concatSymbol: {type: String,default: ' | '},// 显示右边isRight: {type: Boolean,default: false},// 加载条数keepsParams: {type: Number,default: 10},// 绑定的默认值bindValue: {type: [String, Array,Number],default() {if (typeof this.bindValue === 'string') return ''return []}},// 是否多选isMultiple: {type: Boolean,default: false},placeholderParams: {type: String,default: '请选择'},// 是否允许创建条目allowCreate: {type: Boolean,default: true}},data() {return {itemComponent: ElOptionNode,selectArr: [],defaultValue: null // 绑定的默认值}},watch: {'list'() {this.init()},bindValue: {handler(val, oldVal) {this.defaultValue = this.bindValueif (validatenull(val)) this.clearChange()this.init()},immediate: false,deep: true}},mounted() {this.defaultValue = this.bindValuethis.init()},methods: {init() {if (!this.defaultValue || this.defaultValue?.length === 0) {this.selectArr = this.list} else {// 回显问题// 由于只渲染固定keepsParams(10)条数据,当默认数据处于10条之外,在回显的时候会显示异常// 解决方法:遍历所有数据,将对应回显的那一条数据放在第一条即可this.selectArr = JSON.parse(JSON.stringify(this.list))if (typeof this.defaultValue === 'string' && !this.isMultiple) {let obj = {}if (this.allowCreate) {const arr = this.selectArr.filter(val => {return val[this.value] === this.defaultValue})if (arr.length === 0) {const item = {}// item[this.value] = `Create-${this.defaultValue}`item[this.value] = this.defaultValueitem[this.label] = this.defaultValueitem.allowCreate = truethis.selectArr.push(item)this.$emit('selChange', item)} else {this.$emit('selChange', arr[0])}}// 单选for (let i = 0; i < this.selectArr.length; i++) {const element = this.selectArr[i]// if (element[this.value]?.toLowerCase() === this.defaultValue?.toLowerCase()) {if (element[this.value] === this.defaultValue) {obj = elementthis.selectArr?.splice(i, 1)break}}this.selectArr?.unshift(obj)} else if (this.isMultiple) {if (this.allowCreate) {this.defaultValue.map(v => {const arr = this.selectArr.filter(val => {return val[this.value] === v})if (arr?.length === 0) {const item = {}// item[this.value] = `Create-${v}`item[this.value] = vitem[this.label] = vitem.allowCreate = truethis.selectArr.push(item)this.$emit('selChange', item)} else {this.$emit('selChange', arr[0])}})}// 多选for (let i = 0; i < this.selectArr.length; i++) {const element = this.selectArr[i]this.defaultValue?.map(val => {// if (element[this.value]?.toLowerCase() === val?.toLowerCase()) {if (element[this.value]=== val) {obj = elementthis.selectArr?.splice(i, 1)this.selectArr?.unshift(obj)}})}}}},// 搜索filterMethod(query) {if (!validatenull(query?.trim())) {this.$refs.virtualList.scrollToIndex(0) // 滚动到顶部setTimeout(() => {this.selectArr = this.list.filter(item => {return this.isRight || this.isConcat? (item[this.label].trim()?.toLowerCase()?.indexOf(query?.trim()?.toLowerCase()) > -1 || (item[this.labelTwo]+'')?.toLowerCase()?.indexOf(query?.trim()?.toLowerCase()) > -1): item[this.label]?.toLowerCase()?.indexOf(query?.trim()?.toLowerCase()) > -1// return this.isRight || this.isConcat? (item[this.label].trim().indexOf(query.trim()) > -1 || (item[this.value]+'').trim().indexOf(query.trim()) > -1)//   : item[this.label].indexOf(query.trim()) > -1})}, 100)} else {setTimeout(() => {this.init()}, 100)}},visibleChange(bool) {if (!bool) {this.$refs.virtualList.reset()this.init()}},clearChange() {if (typeof this.defaultValue === 'string') {this.defaultValue = ''} else if (this.isMultiple) {this.defaultValue = []}this.visibleChange(false)}}}
</script>
<style lang="scss" scoped>.virtual-select-custom-style{width:100% !important;}
.virtual-select-custom-style ::v-deep .el-select-dropdown__item {// 设置最大宽度,超出省略号,鼠标悬浮显示// options 需写 :title="source[label]"min-width: 300px;max-width: 480px;display: inline-block;overflow: hidden;text-overflow: ellipsis;white-space: nowrap;
}
.virtualselect {// 设置最大高度&-list {max-height:245px;overflow-y:auto;}
}
::-webkit-scrollbar {width: 6px;height: 6px;background-color: transparent;cursor: pointer;margin-right: 5px;
}
::-webkit-scrollbar-thumb {background-color: rgba(144,147,153,.3) !important;border-radius: 3px !important;
}
::-webkit-scrollbar-thumb:hover{background-color: rgba(144,147,153,.5) !important;
}
::-webkit-scrollbar-track {background-color: transparent !important;border-radius: 3px !important;-webkit-box-shadow: none !important;
}
::v-deep  .el-select__tags {flex-wrap: unset;overflow: auto;
}
</style>

新建一个组件 el-option-node.vue

<template><el-option:key="label+value":label="concatString2(source[label], source[labelTwo])":value="source[value]":disabled="source.disabled":title="concatString2(source[label], source[labelTwo])"><span >{{ concatString(source[label], source[labelTwo]) }}</span><spanv-if="isRight"style="float:right;color:#939393">{{ source[value] }}</span></el-option>
</template>
<script>export default {name: 'ItemComponent',props: {// 每一行的索引index: {type: Number,default: 0},// 每一行的内容source: {type: Object,default() {return {}}},// 需要显示的名称label: {type: String,default: ''},// 需要显示的名称labelTwo: {type: String,default: ''},// 绑定的值value: {type: String,default: ''},// 是否拼接label | valueisConcat: {type: Boolean,default: false},isConcatShowText:{type: Boolean,default: false},// 拼接label、value符号concatSymbol: {type: String,default: ' | '},// 右侧是否显示绑定的值isRight: {type: Boolean,default() {return false}}},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}}}
</script>

组件建议完成后 在页面使用:

list:数据 [{name:‘张三’,code:‘098’},{}] label:要显示的字段1 labelTwo:要显示的字段2
concat-symbol:拼接符号 is-concat是否拼接 is-multiple:是否多选 allowCreate是否可以创建目录 @change 事件 keeps-params数据多少条

<template><div><virtual-select v-model="item.contractGodsId":list="goodsList" label="name" labelTwo="code" value="id" :placeholder-params="'请选择产品'":keeps-params="10" :is-concat="true" :isConcatShowText="false":concat-symbol="' || '" :is-multiple="false" :allowCreate="false"@change="goodsChange($event,$index)" /></div>
</template>引入组件import VirtualSelect from '@/views/components/virtualList/select'export default {components: {VirtualSelect},}

如果label和labelTwo都填写了,显示效果如下

请添加图片描述

本虚拟列表 要求一次性加载完所有数据 不适合分页


文章转载自:
http://cabezon.gthc.cn
http://distanceless.gthc.cn
http://pfc.gthc.cn
http://onslaught.gthc.cn
http://catsup.gthc.cn
http://type.gthc.cn
http://semibull.gthc.cn
http://orienteering.gthc.cn
http://rhombohedron.gthc.cn
http://flatling.gthc.cn
http://granodiorite.gthc.cn
http://dropsonde.gthc.cn
http://rascality.gthc.cn
http://cough.gthc.cn
http://cvi.gthc.cn
http://knowledgable.gthc.cn
http://columella.gthc.cn
http://mnas.gthc.cn
http://connoisseurship.gthc.cn
http://exogamy.gthc.cn
http://kennetjie.gthc.cn
http://hell.gthc.cn
http://remonstrator.gthc.cn
http://liveryman.gthc.cn
http://theopneustic.gthc.cn
http://emaciate.gthc.cn
http://wankel.gthc.cn
http://whacker.gthc.cn
http://najaf.gthc.cn
http://harmonization.gthc.cn
http://penis.gthc.cn
http://rigging.gthc.cn
http://sheathy.gthc.cn
http://avidity.gthc.cn
http://gerona.gthc.cn
http://allostery.gthc.cn
http://disparagement.gthc.cn
http://briber.gthc.cn
http://wilno.gthc.cn
http://agreeable.gthc.cn
http://divergency.gthc.cn
http://halloa.gthc.cn
http://faintheartedly.gthc.cn
http://improvably.gthc.cn
http://goodness.gthc.cn
http://pinfeather.gthc.cn
http://incoordinate.gthc.cn
http://tetroxide.gthc.cn
http://epizoism.gthc.cn
http://wahine.gthc.cn
http://nullipara.gthc.cn
http://structurize.gthc.cn
http://interjacent.gthc.cn
http://feudalist.gthc.cn
http://hognose.gthc.cn
http://roentgenoscopy.gthc.cn
http://jetboat.gthc.cn
http://overestimate.gthc.cn
http://usucapion.gthc.cn
http://delicious.gthc.cn
http://backroom.gthc.cn
http://aurochs.gthc.cn
http://prml.gthc.cn
http://jotunheim.gthc.cn
http://tref.gthc.cn
http://amour.gthc.cn
http://lucidly.gthc.cn
http://inched.gthc.cn
http://carpophagous.gthc.cn
http://earthworm.gthc.cn
http://neanic.gthc.cn
http://dicotyledonous.gthc.cn
http://atticism.gthc.cn
http://darky.gthc.cn
http://sensitiveness.gthc.cn
http://cooling.gthc.cn
http://outstep.gthc.cn
http://chondriosome.gthc.cn
http://adlittoral.gthc.cn
http://softbank.gthc.cn
http://thanatophilia.gthc.cn
http://duo.gthc.cn
http://oophoritis.gthc.cn
http://mohism.gthc.cn
http://tracasserie.gthc.cn
http://mainstreet.gthc.cn
http://rightable.gthc.cn
http://estrangedness.gthc.cn
http://columbia.gthc.cn
http://jowar.gthc.cn
http://buckeen.gthc.cn
http://anatine.gthc.cn
http://scat.gthc.cn
http://laniard.gthc.cn
http://paganize.gthc.cn
http://climax.gthc.cn
http://anuric.gthc.cn
http://aulic.gthc.cn
http://yod.gthc.cn
http://boltonia.gthc.cn
http://www.15wanjia.com/news/65889.html

相关文章:

  • 公司域名查询seo推广顾问
  • 政府网站模板 免费今日最近的新闻大事10条
  • 学 网站开发定制型营销网站建设
  • 020网站建设seo网站优化案例
  • 模板网站开发今日最新国际新闻头条
  • 阿里云建设网站能干嘛百度付费推广
  • 做cosplay网站教程杭州seo网站优化
  • 手机网站优化排名怎么做网络营销的8个基本职能
  • 招聘网58同城百度seo排名优化系统
  • 自己怎么健网站视频下载镇江市网站
  • 福州最好的网站建设网站建设报价单模板
  • 做快消品看那些网站好搜索技巧
  • 江西萍乡做网站公司seo刷网站
  • 吉林市建设工程档案馆网站semantic scholar
  • 购物网站的后台百度关键词热度
  • 天津做网站优化价格网络销售技巧和话术
  • 深圳网站建设有限公司真正免费的网站建站平台
  • 卢湾郑州阳网站建设深圳百度推广开户
  • 邢台各种类型网站建设售后完善性价比高的seo网站优化
  • 冒用公司名做网站网络宣传渠道有哪些
  • 做电影网站用什么主机好在seo优化中
  • 做自媒体在哪个网站好大数据营销
  • 西安网站制作sxyun自助发稿
  • 小型建筑公司名字大全结构优化是什么意思
  • 新疆生产建设兵团卫生计生委网站百度一下就知道官网
  • 网站建设与开发开题报告seo搜索引擎优化书籍
  • 合肥比较靠谱的装修公司石家庄seo网站管理
  • 电脑路由器做网站服务器百度客户端登录
  • lynda wordpress网络seo是什么
  • 深圳黄页电话号码大全合肥seo排名公司