element-ui输入框实现滚动触底翻页

template部分:

<el-autocomplete
  prefix-icon="el-icon-search" // 输入框头部图标
  v-model="engineeringName"  // 绑定的值
  :fetch-suggestions="getProjectName"  // 第一次调用回调函数
  placeholder="请选择工程名称"
  @select="handleSelect"  // 选中后调用的事件
  :scrollBottom="handleScrollBottom" // 滚动触底触发回调函数
>
  <template slot-scope="{ item }"> // 插槽展示名称
    <div>
      <p class="orgFullName" :title="item.constructionBidName">
        {{ item.constructionBidName }}
      </p>
    </div>
  </template>
</el-autocomplete>

javaScript部分:

    // 第一次调用的回调
    // pageNo:页码
    // pageSize: 每页条数
    // pageTotal: 总页码
    getProjectName(queryString, callback) {
      this.pageNo = 0;
      const PARAMS = {
        parentProjectId: this.$route.query.etag,
        pageNo: this.pageNo,
        pageSize: 10
      };
      getList(PARAMS).then(res => {
        if (res.status === 200) {
          const { code, data, message } = res.data;
          if (code === "0") {
            const list = data.rows || [];
            this.pageTotal = data.recordsTotal / 10;
            if (this.pageNo < this.pageTotal) {
              this.pageNo++;
            }
            callback(list);
          } else {
            this.$message.error(message);
          }
        }
      });
    },
    // 第二次调用回调
    handleScrollBottom(data, callback) {
      if (this.pageNo > this.pageTotal) return; // 当前页码大于总页码退出回调

      let params = {
        shortName: this.$route.query.etag,
        pageNo: this.pageNo,
        pageSize: 10
      };
      getList(params)
        .then(res => {
          if (res.status === 200) {
            let { code, data, message } = res.data;
            if (code === "0") {
              const list = data.rows || [];
              this.pageNo++; // 页码++
              callback(list);
            } else {
              this.$message.warning(message);
            }
          }
        })
        .catch(err => {
          console.log(err);
        });
    },

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值