完成代码如下:
template

<el-form-item label="车间">
          <el-select
            v-model="form.farmId"
            filterable
            placeholder="请选择"
            v-el-select-loadmore="loadmore"
          >
            <el-option
              v-for="item in options"
              :key="item.id"
              :label="item.farmName"
              :value="item.id"
            >
            </el-option>
          </el-select>
        </el-form-item>

script模块

<script>
export default {
  data() {
    return {
		form: {
        equipmentName: "",
        allCount: "",
        freeCount: "",
        farmId: "",
      },
      options: [],
      pageData: {
        current: 1,
        size: 10,
      },
	}
 },
 mounted() {
    this.options = [];
    this.getdata();
    this.getFarm();
  },
directives: {
    //这个是写到data外面 与mounted同级
    "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: {
    loadmore() {
      this.pageData.current++;
      this.getFarm();
    },
    getFarm() {
      farm({
        page: this.pageData.current,
        limit: this.pageData.size,
      }).then((res) => {
        this.options = [...this.options, ...res.data.page.list];
      });
    },
   }
 }
Logo

旨在为数千万中国开发者提供一个无缝且高效的云端环境,以支持学习、使用和贡献开源项目。

更多推荐