可以输入的下拉框(下拉框数据过大,页面卡死)

项目场景:

提示:这里简述项目相关背景:

在项目中,有些下拉框的数据过于庞大,这样页面有时候会卡死,在vue3中常用的组件库element-puls中有个组件可以避免

在项目中,有些需求要求下拉框选择的同时,可以输入模糊搜索,而且还要求在搜索不到的时候,可以自己手动输入。在vue3中常用的组件库element-puls中同样的,还是这个组件可以做到

模糊搜索,从服务器获取数据


解决方案:

提示:这里填写该问题的具体解决方案:

1:组件

<template>
  <el-select-v2
    v-model="modelValue"
    ref="selectRef"
    :placeholder="props.placeholder"
    :options="options"
    allow-create
    filterable
    remote
    clearable
    :disabled="props.disabled"
    :remote-method="emitUpdateModelValue"
  >
    <template #empty>
      {{ props.emptyPlaceholder }}
    </template>
  </el-select-v2>
</template>
<script lang="ts" setup>
import {getEmil} from "@/api/system/user";

const modelValue = ref()
const emit = defineEmits(['onChange'])
const props = defineProps({
  disabled: {
    type: Boolean,
    default: false
  },
  placeholder: {
    type: String,
  },
  emptyPlaceholder: {
    type: String
  },
  userType:{
    type:Boolean,
    default:false,
  }
})

const emitUpdateModelValue = async (query: string) => {
  if (query) {
    setTimeout(async () => {
      const result = await getEmil({
        userType:props.userType,
        keyword:query
      })
      options.value = result.map((item) => {
        return {
          label: `${item.nickname} (${item.email})`,//昵称加邮箱
          value: `${item.email}`,//主键id
          username: `${item.username}`,//工号
          email: `${item.email}`,//邮箱
          nickname: `${item.nickname}`,//昵称
        }
      })
    }, 200)
  } else {
    options.value = []
  }
}

const options = ref<{
  label: string,
  value: string
}[]>([])

</script>
<style scoped>

</style>

2:使用

<InputSelect
    :userType="false"
    clearable
    v-model="formData.personnelEmail"
    placeholder="请选择或输入" />



import InputSelect from "@/views/components/searchEmail.vue";

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值