el-select实现模糊搜索、远端搜索

el-select实现模糊搜索、远端搜索

实现代码:
VUE 复制代码
<template>
    <div class="item-select-wrapper">
      <el-select v-model="value1" filterable="filterable" :disabled="disabled" remote="remote" clearable="clearable" :remote-method="doSearch"
                 :loading="loading" :size="size">
        <el-option v-for="item in options" :key="item.id" :label="item.name" :value="item.id">
          <div>{{ item.name }}</div>
          <div class="info">{{ item.itemNo }}</div>
        </el-option>
      </el-select>
    </div>
  </template>
  
  <script>
  import { list } from "@/api/list";
  export default {
    name: 'listSelect',
    props: {
      value: {
        type: [String, Number],
        default: null
      },
      size: {
        type: String,
        default: 'small'
      },
      disabled: {
        type: Boolean,
        default: false
      }
    },
    data() {
      return {
        options: [],
        loading: false
      }
    },
    computed: {
      value1: {
        get() {
          return this.value
        },
        set(v) {
          this.$emit('input', v)
        }
      }
    },
    created() {
      this.doSearch();
    },
    methods: {
      doSearch(search) {
        list({search}, {page: 0, size: 20}).then(res => {
          const {content, totalElements} = res
          this.options = content
        })
      }
    }
  }
  </script>
  
  <style lang="stylus">
  
  </style>
  
相关推荐
徐小夕4 分钟前
表格、文档、甘特、大屏、表单一站打通:pxcharts超级表格4.0正式上线!
前端·算法·github
用户5944041035612 分钟前
Vue3 + TypeScript + Leaflet.js 实战:构建企业级地理信息应用
前端
kyson_21 分钟前
一次搭好 ESLint + Prettier + Husky + lint-staged 前端代码工作流
前端
zhifou12345642 分钟前
Vue基础(二)
前端·javascript·vue.js
两只羊ovo1 小时前
手写一个最小版 Claude Code:从任务拆解到 Agent Loop 转起来
前端
给个offer养家糊口1 小时前
抽离 elpis npm 包
前端
默_笙1 小时前
🙃 我让爬虫终于看到了我的网站,后端同事说"这也行?"(下):App Router 全栈实战
前端·javascript
葡萄城技术团队1 小时前
一个单元格放置两个日期选择器:用 SpreadJS CellButtons 录入日期范围
前端
马可家的菠萝2 小时前
自动保存已经有了,为什么笔记软件还需要“历史版本”?
前端·后端·架构
半个落月3 小时前
从 "use client" 到 Route Handler:用 Todos 理解 Next.js 水合与全栈请求
前端·react.js·next.js