el-select可输入下拉框限制长度

el-select可输入或可输入创建限制长度
可创建自定义指令v-Length=“50”,限制输入最大长度为50

<el-select
    v-model="JSDW"
    filterable
    clearable
    v-limitLength="50"
    allow-create
    default-first-option
    style="width:100%">
    <el-option
        v-for="(item, index) in ListJSDW"
        :key="index"
        :label="item"
        :value="item">
    </el-option>
</el-select>

局部创建自定义指令

created() {
   

},
// 控制-select输入长度 自定义指令
// 控制-select输入长度 自定义指令
 directives: {
   
     limitLength: {
   
         bind: function (el, binding, vnode) {
   
             const input = el.getElementsByTagName('input')[0]
             if (input) {
   
                 input.setAttribute('maxlength', binding.value)
             }
         }
     }
 },
mounted() {
   

},

全局创建自定义指令,在main.js里

Vue.directive('limitLength',{
   
    inserted: function (el, binding, vnode) {
   
        const input = el.getElementsByTagName('input')[0]
        if (input) {
   
            input.setAttribute('maxlength', binding.value)
        }
    }
})

可直接复制使用

最近更新

  1. TCP协议是安全的吗?

    2023-12-28 11:38:02       16 阅读
  2. 阿里云服务器执行yum,一直下载docker-ce-stable失败

    2023-12-28 11:38:02       16 阅读
  3. 【Python教程】压缩PDF文件大小

    2023-12-28 11:38:02       15 阅读
  4. 通过文章id递归查询所有评论(xml)

    2023-12-28 11:38:02       18 阅读

热门阅读

  1. vue 预览 pdf、word、excel

    2023-12-28 11:38:02       41 阅读
  2. Vue 3 中安装并使用 Axios 详细步骤+样例代码详解

    2023-12-28 11:38:02       31 阅读
  3. Ajax

    2023-12-28 11:38:02       29 阅读
  4. PDF.js介绍以及使用

    2023-12-28 11:38:02       38 阅读
  5. PDF是什么格式的文件

    2023-12-28 11:38:02       37 阅读
  6. Unity相机跟随角色移动

    2023-12-28 11:38:02       33 阅读
  7. C# JsonString转Object以及Object转JsonString

    2023-12-28 11:38:02       34 阅读
  8. C++ list的模拟实现

    2023-12-28 11:38:02       30 阅读