美文网首页
2024-01-06 el-select 无限下拉滚动加载数据

2024-01-06 el-select 无限下拉滚动加载数据

作者: 半眼鱼 | 来源:发表于2024-01-05 11:43 被阅读0次

html

          <div>
              <el-select style="width: 300px;" @visible-change="seeChange" v-el-select-loadmore="loadmoreData" v-model="switchShopIdValue"
                placeholder="请选择店铺" @change="changeShopInfo" filterable remote reserve-keyword
                :remote-method="remoteMethod" :loading="loading">
                <el-option v-for="item in shopList" :key="item.id" :label="item.name" :value="item.id">
                </el-option>
              </el-select>
            </div>

script

  directives: {//注意:这个是写到data外面
    'el-select-loadmore': {
      bind(el, binding) {
        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
          if (condition) {
            binding.value()
          }
        })
      }
    },
  },

methods

    seeChange(val) {
      if (!val) {
        this.keyWord = ''
      }
    },
    // 懒加载
    loadmoreData() {
      if (this.loadmore) {
        this.page.current = this.page.current + 1;
        this.getShopList();
      }
    },
    // //店铺选择
    changeShopInfo(e) {
      this.shopId = e;
    },
    remoteMethod(query) {
      this.keyWord = query
      if (query != "") {
        this.loading = true;
        getShopList({
          current: 1,
          size: 12, name: query
        }).then((res) => {
          let shopList = res.data.data.records
          this.shopList = shopList;
          if (shopList.length > 0) {
            this.changeShopInfo(shopList[0].id);
          }
          this.getShopInfo(this.switchShopId)
          this.loading = false;
        });
      }
    },
    getShopList() {
      // this.loading = true;
      getShopList(Object.assign({ name: this.keyWord }, this.page)).then(response => {
        let dataList = response.data.data.records;
        this.shopList = [...this.shopList, ...dataList];
        if (dataList.length < this.page.size) {
          this.loadmore = false;
        }
        this.getShopInfo(this.switchShopId)

        // this.loading = false;
        //let storeSwitchShopId = getStore({name: 'switchShopId'})
        // if (shopList.length > 0
        //   && (!storeSwitchShopId || this.shopList.findIndex(item => item.id === storeSwitchShopId) == -1)) {
        //   //没有切换租户或没有绑定该切换租户,则默认切换到第一个租户
        //   setStore({
        //     name: 'switchTenantId',
        //     content: tenantListMy[0].id
        //   })
        //   this.switchTenantId = tenantListMy[0].id
        //   setTimeout(() => {
        //     this.$router.go(0)
        //   }, 500);
        // }
      })
    },

相关文章

  • web前端:交互

    手势 swipe滚动 移动web滚动如何更smoothtouch 下拉刷新上拉/触底加载无限滚动懒加载 传统web...

  • 无限下拉滚动Vs分页

    一、无线下拉滚动 无限下拉加载技术使用户在大量成块的内容面前一直滚动查看。这种方法是在你向下滚动的时候不断加载新内...

  • 2017-4-5_工作报告

    工作报告 修复汇车滚动加载bug 下拉刷新重新加载数据后,没有清空旧的数据滚动加载时把旧数据和新数据拼接在一起了。...

  • vue下拉、上拉和无限滚动组件

    vue插件vuu-pull@1.0.4 Vuu-Pull@1.0.4 一个集成了下拉刷新、上拉加载、无限滚动加载的...

  • Vue+Element-ui<InfiniteScroll

    效果图: 之前用的时Mint-ui里面的下拉滚动加载,现在Element-ui在2.10.1版本中也有了无限滚动加...

  • 下拉加载

    实现元素滚动到最底或下拉时加载

  • 未设置estimatedRowHeight引发MJFooter无

    未设置estimatedRowHeight引发MJFooter无限下拉加载

  • 页面无限滚动实现原理

    前端无限滚动一般指元素滚动到最后,动态加载更多数据。实现原理大只如下:假设outer为外层容器, 则当滚动条滚动到...

  • Antd Table 下拉加载数据

    背景 使用react+antd开发 下拉加载更多数据 Antd的Table组件本身是不提供滚动事件的;在开发时,...

  • Flutter下拉刷新、上拉加载

    1、Flutter下拉刷新、上拉加载 注意: 滚动组件添加: physics: ClampingScrollPh...

网友评论

      本文标题:2024-01-06 el-select 无限下拉滚动加载数据

      本文链接:https://www.haomeiwen.com/subject/zvhindtx.html