el-select加上搜索查询时,限制开头空格输入

**1、注释:**结构中的ref和@input.native很重要

<el-form-item label="商品类型:" prop="productType">
   <el-select
     ref="eleSelect" //这里很重要1
     v-model.trim="formData.productType"
     placeholder="请选择"
     filterable
     clearable
     @input.native="trimSelect"  //这里很重要2
   >
     <el-option
       v-for="item in dictList.SPLX"
       :key="item.dictId"
       :label="item.dictLabel"
       :value="item.dictValue"
     ></el-option>
     
 </el-select>
</el-form-item>

2、js中限制开头为空格时重新赋值为空

  // 开头为空格时重新赋值为空
  const eleSelect = ref()
  const trimSelect = ()=>{
   
    let regex = /^\s*$/;
    if(regex.test(eleSelect.value.selectedLabel)){
   
       eleSelect.value.selectedLabel = ''
    }
  }

相关推荐

最近更新

  1. docker php8.1+nginx base 镜像 dockerfile 配置

    2024-02-22 15:28:01       94 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2024-02-22 15:28:01       100 阅读
  3. 在Django里面运行非项目文件

    2024-02-22 15:28:01       82 阅读
  4. Python语言-面向对象

    2024-02-22 15:28:01       91 阅读

热门阅读

  1. 微众银行:始于数字原生,立于普惠金融

    2024-02-22 15:28:01       53 阅读
  2. 主流无人机开源飞控

    2024-02-22 15:28:01       53 阅读
  3. 大模型中的token是什么?

    2024-02-22 15:28:01       52 阅读
  4. windows命令行加入与移除管理员组

    2024-02-22 15:28:01       57 阅读
  5. SpringBoot项目启动后执行指定方法的四种实现

    2024-02-22 15:28:01       53 阅读
  6. react中useState、setState、usemeno、meno区别

    2024-02-22 15:28:01       47 阅读