el-select:loadMore加载更多功能

参考:
https://www.jianshu.com/p/74dda01d2faf
https://blog.csdn.net/qq_41287158/article/details/125046149
https://blog.csdn.net/cherry_zhang18/article/details/120907452

问题:

  1. 回显问题
<el-select v-model="searchParams.productCode"
           placeholder="请选择产品"
           clearable
           filterable
           v-loadmore="loadMore"
           @change="changeProduct">
  <el-option v-for="item in productList"
             :key="item.code"
             :label="item.name"
             :value="item.code">
  </el-option>
  <!--加载中的item不可选中状态-->
  <el-option v-if="isLoading" disabled>
    加载中-Loading...
  </el-option>
</el-select>

// data
productList: [], // List
productPagination: { // 分页信息
  current: 1,
  size: 10,
  total: 0,
},
isLoading: false, // 是否加载中


/***
 * 加载更多
 */
loadMore () {
  console.log('loadMore执行了')
  // 如果正在加载中的时候,直接return,防止网速慢,一次加载很多页的问题
  if (this.isLoading) {
    return false
  }
  if (this.productPagination.total > this.productList.length) {
    this.productPagination.current += 1
    this.getProductList()
  }
},
/**
 * 获取产品列表 list
 */
async getProductList () {
  const params = {
    current: this.productPagination.current,
    size: this.productPagination.size,
  }

  this.isLoading = true
  let res = await getProductList(params) // getDeviceList

  if (this.productPagination.current == 1) {
    this.productList = res.data.records || []
  } else {
    this.productList.push(...res.data.records || [])
  }
  this.isLoading = false
  this.productPagination.total = res.data.total || 0
},
// 指令
directives: {
  'loadmore': {
    bind (el, binding) {
      console.log('el:', el)
      console.log('binding:', binding.value)
      const selectDom = el.querySelector('.el-select-dropdown .el-select-dropdown__wrap')
      selectDom.addEventListener('scroll', () => {
        /**
         * scrollHeight 获取元素内容高度(只读)
         * scrollTop 获取或者设置元素的偏移值,常用于, 计算滚动条的位置, 当一个元素的容器没有产生垂直方向的滚动条, 那它的scrollTop的值默认为0.
         * clientHeight 读取元素的可见高度(只读)
         * 如果元素滚动到底, 下面等式返回true, 没有则返回false:
         * ele.scrollHeight - ele.scrollTop === ele.clientHeight;
         */
        console.log('scrollHeight:', selectDom.scrollHeight, 'scrollTop:', selectDom.scrollTop, 'clientHeight:', selectDom.clientHeight)
        const condition = selectDom.scrollHeight - selectDom.scrollTop <= selectDom.clientHeight
        if (condition) {
          binding.value()
        }
      })
    }

  }
},

问题:
1.如果select是模糊搜索,怎么记录搜索的内容呢?

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值