数据过多,select优化

封装Select组件

<template>
  <div>
    <el-select
      ref="selectRef"
      v-bind="$attrs"
      v-on="$listeners"
      clearable
      filterable
      remote
    >
      <div class="option">
        <el-option
          v-for="(item, index) in options"
          :key="index"
          :label="item.label"
          :value="item.value"
        >
        </el-option>
      </div>
      <div class="pagin">
        <el-pagination
          small
          background
          layout="prev,pager,next,total"
          v-bind="$attrs"
          v-on="$listeners"
        ></el-pagination>
      </div>
    </el-select>
  </div>
</template>

<script>
export default {
  props: {
    options: {
      type: Array,
      default: ()=>[]
    },
  },
    data() {
        return {
          
        }
    },
};
</script>

<style lang="scss" scoped>
.option{
    min-height: 50px;
    height: auto;
    max-height: 150px;
    overflow-y: auto;
}
.pagin{
    background:#fff;
}
::-webkit-scrollbar{
    width: 2px;
}
</style>


使用

 <EverSelect
          :page-size="selectParam.pageSize"
          :total="selectParam.total"
          :current-page="selectParam.currentPage"
          :options="selectList"
          @change="selectChange"
          :value="form.data.productName"
          :remote-method="remoteSearch"
          :hide-on-single-page="true"
        />

   // 远程搜索
    remoteSearch(val) {
      this.getList({
        page: this.selectParam.pageNum,
        rows: this.selectParam.pageSize,
        productBusinessTypeIds: [1, 3, 4],
        productName:val
      });
    },
    //选取item
selectChange(val){
      let info = this.selectList.find(item=> item.id ==val)
      this.$set(this.form.data, "productId", info.id);
      this.$set(this.form.data, "numberType", "1");
      this.$set(
        this.form.data,
        "productBusinessTypeId",
        info.productBusinessTypeId
      );
      this.$set(this.form.data, "productName", info.productName);
      this.$set(this.form.data, "productNum", info.productNum);
    },
    /* 切换页 */
    currentPage(val) {
      this.$set(this.selectParam, "pageNum", val);
      this.getList()
    },
  getList() {
      let param = {
        page: this.selectParam.pageNum,
        rows: this.selectParam.pageSize,
        productBusinessTypeIds: [1, 3, 4],
      };
      requestData("toChooseListQueryPageDigital", param).then((res) => {
        if (res.code == 1000) {
         this.selectList = res.data.records.map(item=>{
           return {
             ...item,
             label:item.productName,
             value:item.id,
           }
          })
          this.$set(this.selectParam, "total",res.data.total);
          this.$set(this.selectParam, "currentPage",res.data.pages);
        }
      });
    },

效果图
在这里插入图片描述

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值