el-select下拉数据实时查询(分页查询 滚动加载)

本文介绍了一个基于Element UI的产品选择组件实现细节,包括如何通过远程搜索加载产品列表,并实现了列表的滚动加载更多功能。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

<template>	
            <el-form-item label="产品" prop="productCode">
              <el-select v-model="form.productCode" placeholder="请选择产品" filterable remote :remote-method="queryProduct" clearable @focus="(event)=>queryProduct()" v-loadmore="loadMore"
                style="width: 100%" @change="setProductInfo">
                <el-option v-for="(s,index) in productList" :key="index" :label="s.cdesc" :value="s.itemno">
                  <name-code :name="s.itemno" :code="s.cdesc" />
                </el-option>
              </el-select>
            </el-form-item>
</template>


<script>
import { listProduct } from '@/api/baseData/product'
export default {
 data(){
    return{
      //产品代码下拉列表加载
      loadProduct: false,
      //产品代码列表
      productList: [],
      productQueryParams: {
        status: 'T',
        searchValue: null,
        pageNum: 1,
        pageSize: 20,
      },
      proTotal: 0,	
    }
  }, 
  created() {
    this.getList()
    this.queryCurreny()
    this.querySp()
    this.queryProduct()
    // this.queryQuotation()
    this.tableHeight = this.changeHeight()
    listUnit({ corpId: this.$store.getters.corpid }).then((res) => {
      this.unitList = res.rows
    })
  }, 
methods:{

    /** 查询产品列表 */
    queryProduct(v) {
      this.loadProduct = true
      this.productQueryParams.searchValue = v
      this.productQueryParams.pageNum = 1
      listProduct(this.productQueryParams).then((res) => {
        this.productList = res.rows
        this.loadProduct = false
        this.proTotal = res.total
      })
    },
    
    loadMore() {
      if (this.proTotal == this.productList.length) {
        return
      }
      this.loadProduct = true
      let totalPage =
        parseInt(this.proTotal / 20) + (Number(this.proTotal) % 20 > 0 ? 1 : 0)
      if (this.productQueryParams.pageNum + 1 <= totalPage) {
        this.productQueryParams.pageNum = this.productQueryParams.pageNum + 1
        listProduct(this.productQueryParams).then((res) => {
          this.productList = this.productList.concat(res.rows)
          this.loadProduct = false
        })
      }
    },
} 
}
</script>

好的,以下是一个简单的实现代码,您可以参考一下: ```vue <template> <div> <el-select v-model="selected" filterable @change="handleSelectChange" remote :remote-method="remoteMethod"> <el-option v-for="item in options" :key="item.value" :label="item.label" :value="item.value" /> </el-select> <el-pagination :current-page.sync="currentPage" :page-size="pageSize" :total="total" @current-change="handlePageChange" /> </div> </template> <script> export default { data() { return { selected: '', options: [], currentPage: 1, pageSize: 10, total: 0 } }, methods: { // 远程搜索方法 remoteMethod(query) { // 发送请求获取对应的数据 axios.get('/api/options', { params: { query, page: this.currentPage, pageSize: this.pageSize } }).then(response => { const { data, total } = response.data this.options = data this.total = total }).catch(error => { console.log(error) }) }, // 选择发生变化 handleSelectChange() { console.log(this.selected) }, // 分页发生变化 handlePageChange(current) { this.currentPage = current this.remoteMethod('') } } } </script> ``` 在这个代码中,我们使用了 Element UI 中的 el-selectel-pagination 组件来实现分页下拉框。我们通过 el-select 的 filterable 属性来开启模糊搜索功能,通过 remote 属性来开启远程搜索功能。我们使用了 axios 发送异步请求来获取后端返回的数据,并将数据渲染到 el-select 中。我们使用 el-pagination 组件来实现分页功能,当用户选择不同的页码时,我们会发送请求获取对应的数据,再将数据渲染到 el-select 中。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值