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

el-select可输入或可输入创建限制长度

可创建自定义指令v-Length="50",限制输入最大长度为50

javascript 复制代码
<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>

局部创建自定义指令

javascript 复制代码
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里

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

可直接复制使用

相关推荐
码云数智-园园4 分钟前
HTML5 FileReader 读取本地文件,前端上传预览原理
前端·html·html5
恋猫de小郭8 分钟前
Flutter Analyzer ,这玩意还有这么大的优化空间
android·前端·flutter
夕水18 分钟前
夕水文学网502 故障 —— 爬虫把 Node 堆内存吃爆
javascript·后端·node.js
honkun625 分钟前
vue 表格组件 vxe-table 行拖拽排序时,为“拖拽为子级”增加操作提示
前端·javascript·vue.js·vxe-table
qinqinzqq36 分钟前
CSS Grid 命名区域布局:组件 Header / Content / Sider 两栏布局实践
前端·css
斯内普吖41 分钟前
(开源)智慧物业管理系统实战指南 基于 Python + Django + uni-app + Vue + MySQL
vue.js·python·django·uni-app·开源
总要学点什么1 小时前
第127篇:河道流场水面——把整条河的流向烤进一张贴图
开发语言·javascript·microsoft·材质·贴图·cesium
子非鱼a1 小时前
【WEB】[NewStarCTF 公开赛赛道]IncludeOne
前端·php
油丶酸萝卜别吃1 小时前
Vue2 实现全局主题切换功能:CSS Variables + Vuex
开发语言·前端·javascript
-梅1 小时前
Chrome 内存泄漏诊断指南:从现象定位到根因排查
前端·chrome