el-select 数据懒加载

1.使用全局引入

在utils文件夹中写好directives.js

import Vue from 'vue'

Vue.directive("el-select-loadmore", {

  bind (el, binding) {

    // 获取element-ui定义好的scroll盒子

    const SELECTWRAP_DOM = el.querySelector('.el-select-dropdown .el-select-dropdown__wrap');

    SELECTWRAP_DOM.addEventListener('scroll', function () {

      const CONDITION = this.scrollHeight - this.scrollTop <= (this.clientHeight + 2);//因为我的每次差1px,我就加了2

      if (CONDITION) {

        binding.value()

      }

    })

  }

})

2.全局引入import '@/utils/directives.js'//select数据懒加载

3.组件中使用

上代码

  loadmore1(){
    let index=this.plateName.pageNum++;//滚动时页码自动+1
    if(index * this.plateName.pageSize < this.totalSeletnNum) {
          this.getPlatformNameList()
    } },
//请求的数据也是分页式的  totalSeletnNum 代表着总条数 ; index * this.plateName.pageSize < this.totalSeletnNum  计算请求的截至条件
//请求接口
  getPlatformNameList(){
        this.plateName.data =this.queryParams.data.platformName
         getPlatformNameList(this.plateName).then(res=>{
           this.plateList = [... this.plateList, ...res.data.content];
           this.totalSeletnNum = res.data.totalSize
         }).catch(function () {
            
         })
      },

//关键字请求
   getDataplateName(keyword){
           this.queryParams.data.platformName = keyword
           this.plateList=[],
            this.plateName.pageNum=1,
           this.getPlatformNameList()  
        },
/

特别感谢工作中帮助我的同事以及对我的包容,差不多一周搞好这一个功能,若能帮助到大家我很高兴

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值