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>
  
相关推荐
徐小夕38 分钟前
jitword 协同文档3.2发布:打造浏览器中最强word编辑器
前端·架构·github
纯爱掌门人2 小时前
干了这么多年前端,聊聊 2026 年我们到底还值不值钱
前端·程序员
houhou2 小时前
Monaco Editor 集成指南:从配置到优化
前端
hunterandroid2 小时前
[Android 从零到一] Custom View 自定义绘制:从 onDraw 到完整交互
前端
李明卫杭州2 小时前
Vue3 v-memo 指令详解:让你的列表渲染性能翻倍 🚀
前端
梨子同志2 小时前
Monorepo
前端
lihaozecq3 小时前
继 Web Coding Agent 后,我做了一个本地优先的桌面 AI Agent
前端·agent
用户298698530143 小时前
在 React 中使用 JavaScript 将 Excel 转换为 SVG
前端·javascript·react.js
CodingSpace3 小时前
ESLint
前端
Csvn3 小时前
异步错误捕获的六大陷阱:await 裹着 try-catch 就一定稳了吗?
前端