el-select可输入限制输入的字数

el-select创建条目以及远程搜索

复制代码
            <el-select
              v-model="form.constructionName"
              placeholder="请输入"
              style="width: 400px"
              allow-create
              default-first-option
              filterable
              remote
              reserve-keyword
              :remote-method="remoteMethod1"
              :loading="loading"
              ref="sgSelect"
              @input.native="sgfilterData"
            >
              <el-option
                v-for="item in constructionoptions"
                :key="item.name"
                :label="item.name"
                :value="item.name"
              >
              </el-option>
            </el-select>

限制下拉框输入字数

  1. ref="sgSelect"

  2. @input.native="sgfilterData"

  3. 如下方法,就over了

    methods:{
    sgfilterData() {
    var str = this.refs.sgSelect.data.selectedLabel; // 此属性得到输入的文字
    // 控制的js
    if (str.length > 20) {
    this.refs.sgSelect.data.selectedLabel = str.substr(0, 20);
    }
    },

    }

相关推荐
是烟花哈4 小时前
【前端】React框架学习
前端·学习·react.js
qq4356947014 小时前
JavaWeb08
前端
2401_878454535 小时前
html和css的复习(1)
前端·css·html
@PHARAOH6 小时前
WHAT - git worktree 概念
前端·git
IT_陈寒6 小时前
我竟然被JavaScript的隐式类型转换坑了三天!
前端·人工智能·后端
我亚索贼六丶6 小时前
二十六. AI基础概念之如何更好的使用AI
前端
小码哥_常6 小时前
安卓启动页Logo适配秘籍:告别“奇形怪状”的展示
前端
我亚索贼六丶6 小时前
二十五.Electron 初体验与进阶
前端
当时只道寻常6 小时前
像使用 Redis 一样操作 LocalStorage
前端·前端工程化
RONIN6 小时前
UI组件库elementplus
前端